bar-chart

How to annotate a pandas stacked bar, with more than 2 stacks?

孤街浪徒 提交于 2020-08-19 11:07:13
问题 I have the following dataset that contains weekly information for 4 different levels. I created a stacked bar chart, each stack representing a level, and each bar a week. How can I add the values corresponding to each color on chart? import numpy as np import pandas as pd import matplotlib as plt plt.style.use('ggplot') %matplotlib inline rng=pd.date_range('2020-01-02', periods=10,freq='7D') level=['low', 'medium', 'high', 'very_high'] values=np.random.randint(1, 100, size=(10, 4)) df=pd

How to annotate a pandas stacked bar, with more than 2 stacks?

徘徊边缘 提交于 2020-08-19 11:02:10
问题 I have the following dataset that contains weekly information for 4 different levels. I created a stacked bar chart, each stack representing a level, and each bar a week. How can I add the values corresponding to each color on chart? import numpy as np import pandas as pd import matplotlib as plt plt.style.use('ggplot') %matplotlib inline rng=pd.date_range('2020-01-02', periods=10,freq='7D') level=['low', 'medium', 'high', 'very_high'] values=np.random.randint(1, 100, size=(10, 4)) df=pd

How can I add hatches, stripes or another pattern or texture to a barplot in ggplot?

痴心易碎 提交于 2020-08-05 09:35:24
问题 Suppose I have data with both an ordinal variable and a categorical variable: set.seed(35) df <- data.frame(Class = factor(rep(c(1,2),times = 80), labels = c("Math","Science")), StudyTime = factor(sort(sample(1:4, 16, prob = c(0.25,0.3,0.3,0.15), replace = TRUE)),labels = c("<5","5-10","10-20",">20")), Nerd = factor(sapply(rep(c(0.1,0.3,0.5,0.8),c(30,50,50,30)), function(x)sample(c("Nerd","NotNerd"),size = 1, prob = c(x,1-x))),levels = c("NotNerd","Nerd"))) One could use ggplot and geom_bar