Jonas
Jonas

Reputation: 133

Matplotlib: Increase figure height & plot spacing (is there a max fixsize?)

I have a matplotlib plot of >200 vertical bar charts.

# first line of code:
fig, ax = plt.subplots(figsize=(5, 100), dpi=150)

Despite setting the figsize to huge values, it does not apply the value and the chart gets crammed with overlapping rows:

enter image description here

I am using matplotlib 3.3.3 and Python 3.9.1. The issue occures both when executing the python script via command line and pyCharm.

I also tried exporting as PDF using fig.savefig(pdfpath, bbox_inches='tight') but it looks the same.

What do I need to change? Is there a maximum figsize? Does my screen resolution/size limit the max figsize?

Edit: If I set figsize to even lager value, e.g. 4000 inches, then I run into error "Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize"

Upvotes: 1

Views: 3068

Answers (1)

Jonas
Jonas

Reputation: 133

Ok, it seems that my screen resolution is actually limiting the figure size.

If I change the code secuence to first plot and save as PDF, then show the plot on screen, I get different results:

plt.plot()
fig.savefig(pdfpath, bbox_inches='tight')
plt.show()

enter image description here

Upvotes: 1

Related Questions