将图形大小设置为大于matplotlib中的屏幕大小 [英] Setting figure size to be larger than screen size in matplotlib

查看:86
本文介绍了将图形大小设置为大于matplotlib中的屏幕大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 matplotlib 中创建能很好地在期刊文章中阅读的图形.我有一些较大的数字(带有子图),我希望以纵向模式占用几乎整个页面(特别是,对于在美国信纸上留有1英寸页边距的整页数字,为6.5"x9").我可以设置使用 figsize 参数可以轻松地实现图形尺寸.但是,如果将图形尺寸设置为大于屏幕尺寸(我使用的是13英寸笔记本电脑),则将压缩图形.具体来说,高度是一个问题.只要下面的 height 参数大于屏幕的高度,保存的图形的尺寸就不会更改:

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

即使超出屏幕尺寸,如何使 matplotlib 使用所要求的图形尺寸?我正在使用spyder.

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

推荐答案

这可能与生成绘图的后端有关.

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')

请注意,此操作必须在导入 matplotlib.pyplot 之前运行.

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

这篇关于将图形大小设置为大于matplotlib中的屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆