I'm making a simple horizontal stacked bar plot:
df = pd.DataFrame({'firstBox':firstL,'secondBox':secondL,'thirdBox':thirdL})
ax = df.plot.barh(stacked=True)
ax.set_title("My Example Plot")
ax.set_yticklabels(labels=['A label this long is cut off','this label is also cut off])
plt.show()
but the values on my ytick labels are being cut off. If I increase the width of the returned plot window, I can see slightly more of them, but I need to stretch the window well past the width of my monitor to see the entire label. Is there a way to just push the plot to the right to include my long labels?
Thanks!
You should try this:
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})
In case you are using savefig, bbox_inches='tight'
is an option that automatically try to figure out the tight bbox of the figure.
You can use ax.get_figure().tight_layout()
or plt.gcf().tight_layout()
. This will fix the figure layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With