如何以最大窗口形式而不是默认大小保存 matplotlib 图? [英] How to save matplotlib figure in max windows form instead of default size?

查看:58
本文介绍了如何以最大窗口形式而不是默认大小保存 matplotlib 图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道我应该如何解决?我知道有一个可以手动执行的保存按钮,但是我正在绘制100多个图形,所以我希望会有一种自动执行此操作的方法?

Anyone know how should i work around with that? I know there is save button which I could do it manually but I am plotting 100+ graph so I hope there will be a way to doing it automatically?

我使用的是TkAgg"后端,我在寻找任何可能的解决方案.通过在我的绘图功能的末尾使用以下内容.

I was using 'TkAgg' backend and I look up for any possible solution around. By using the following at the end of my plot function.

manager = plt.get_current_fig_manager() 
manager.resize(*manager.window.maxsize()) 
plt.savefig(r'C:\Users\310293649\Desktop\PlotFigure\TESTING.png')
plt.show()

也尝试过这个,但我仍然能够以我喜欢的理想方式 plt.show() 图形,即完整的窗口大小.但这仍然会自动以最小的默认格式保存我的所有身影.

wm = plt.get_current_fig_manager()
wm.window.state('zoomed')
plt.savefig(r'C:\Users\310293649\Desktop\PlotFigure\TESTING.png')
plt.show()

下面是我从上面的命令 plt.show() 之后得到的,

Below is what I got after plt.show() from above command,

我得到的 plt.savefig 结果:

plt.savefig result that I got:

如您所见代码设法以最大窗口大小显示绘图,但它仍然自动以默认大小保存绘图所以我想知道是否可能或是否有任何解决方案可以保存最大窗口大小中的matplotlib数字是否自动 ?还是我无法做到这一点?

As you can see The code managed to show the plot in max windows size but it still automatically saved the plot with default size So I was wondering if it is possible or is there any solution to save the matplotlib figure in max windows size automatically? OR there is no way I can do that?

下面的图像是我使用matplotlib中的保存图形按钮手动完成时的图形:

Below images is the figure when I done it manually with the save figure button in matplotlib:

-此处的大多数答案是指以全窗口形式显示该图,但是在保存时最大窗口自动(它仍然以正常大小保存)......你可以看到问题的作者在所有答案的评论部分提出了这个问题但没有回答.

How to make pylab.savefig() save image for 'maximized' window instead of default size - Most of the answer here refer to showing the figure in full windows form but when it come to saving the max windows automatically(it still save it in the normal size)...you can see the author of the ques have raised up the issue in the comment section of all of the answer but was not answered.

推荐答案

显然,这是Matplotlib 2.0('17年1月)中引入的错误.

Apparently, this is a bug introduced in Matplotlib 2.0 (January '17).

此处这里.

似乎有一个相当简单的代码更改来解决这个这里,但是您必须自己应用它,因为它尚未包含在任何已发布版本中(计划用于 2.1.1 2.2).

There seems to be a fairly simple code change to fix this here, but you'll have to apply it yourself since it's not included in any released version yet (it's planned for 2.1.1 2.2).

这篇关于如何以最大窗口形式而不是默认大小保存 matplotlib 图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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