Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

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"

question from:https://stackoverflow.com/questions/65883665/matplotlib-increase-figure-height-plot-spacing-is-there-a-max-fixsize

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...