I want to plot a stacked-bar graph with data coming from two separate dataframes in pandas (My_means and My_stds). I am using Python 3.7.
The plotting call works fine, however, the labels are cut-off. Setting tight_layout does not help me and generates an "Attribute Error: 'AxesSubplot' object has no attribute 'tight_layout'". What does this mean and how do I overcome this?
I haven´t found any problems related to this error, so I assume I am doing something rather stupid...
Here is my code:
My_means= ratios.pivot_table('Data', 'Sample ID', 'User ID', aggfunc= np.mean)
My_stds= ratios.pivot_table('Data', 'Sample ID', 'User ID', aggfunc= np.std)
plot_it = My_means.plot(kind='bar', color=stack_cols, stacked=True, yerr=My_stds, capsize=3, title='Just some graph')
plot_it.tight_layout()
Thanks for your help! Jazz
tight_layouton an axes, you ned to do it on a figure. Most often done usingplt.tight_layout()plot_itis the axes, not the figure. If you have doneimport matplotlib.pyplot as pltthen you can simply doplt.tight_layout()