python - pandas - plotting integration with matplotlib -


given data frame:

xlabel = list('xxxxxxyyyyyyzzzzzz') fill= list('abc'*6) val = np.random.rand(18) df = pd.dataframe({ 'xlabel':xlabel, 'fill':fill, 'val':val}) 

this i'm aiming at: http://matplotlib.org/mpl_examples/pylab_examples/barchart_demo.png

applied example, group x, y , z, gender a, b , c, , scores val.

i'm aware in pandas plotting integration matplotlib still work in progress, possible directly in matplotlib?

is want?

df.groupby(['fill', 'xlabel']).mean().unstack().plot(kind='bar') 

or

df.pivot_table(rows='fill', cols='xlabel', values='val').plot(kind='bar') 

you can brake apart , fiddle labels , columns , title, think gives plot wanted.

for error bars you'll have go mpl directly.

mean_df = df.pivot_table(rows='fill', cols='xlabel',                          values='val', aggfunc='mean') err_df = df.pivot_table(rows='fill', cols='xlabel',                         values='val', aggfunc='std')  rows = len(mean_df) cols = len(mean_df.columns) ind = np.arange(rows) width = 0.8 / cols colors = 'grb'  fig, ax = plt.subplots() i, col in enumerate(mean_df.columns):     ax.bar(ind + * width, mean_df[col], width=width,            color=colors[i], yerr=err_df[col], label=col)  ax.set_xticks(ind + cols / 2.0 * width) ax.set_xticklabels(mean_df.index) ax.legend() 

but there enhancement, in 0.13: issue 3796


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -