Setting figure size to be larger than screen size in matplotlib

吃可爱长大的小学妹 提交于 2021-01-03 17:01:15

问题


I'm trying to create figures in matplotlib that read nicely in a journal article. I have some larger figures (with subfigures) that I'd like to take up nearly an entire page in portrait mode (specifically, 6.5"x9" for a full-page figure with 1" margins on US letter paper). I can set the figure size easily with the figsize parameter. However, the figure is compressed if I set the figure size to be larger than my screen size (I'm working on a 13" laptop); specifically, the height is an issue. The dimensions of the saved figure do not change as long as the height parameter below is larger than the height of my screen:

height = 9
fig, ax = plt.subplots(3, 2, figsize=(6.5, height))
plt.savefig('test.png') # size of this figure is independent of height
                        # if height > height of my screen

How can I make matplotlib use the requested figure size even when it exceeds my screen's dimensions? I'm using spyder.


回答1:


This is likely an issue with your backend for plot generation.

You can see what backend you are using by running:

import matplotlib; matplotlib.get_backend()

Try changing the backend to something else, for example:

import matplotlib

matplotlib.use('Agg')

Note that this has to be run before importing matplotlib.pyplot.



来源:https://stackoverflow.com/questions/55566198/setting-figure-size-to-be-larger-than-screen-size-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!