【Spinning up】2.1、将Matplotlib自动全屏显示和保存图像(Saving Matplotlib graphs to image as full screen)

2.1、将Matplotlib自动全屏显示和保存图像(Saving Matplotlib graphs to image as full screen)

前言:

每次matplotlib画图都是一个小图,然后手动调整为全屏,再手动调整图片的位置,简直恶心透了。
今天趁机将自动全屏的问题解决了。
在这里插入图片描述

参考链接:

将Matplotlib图形保存为全屏图像(Saving Matplotlib graphs to image as full screen)

解决方案

The method you use to maximise the window size depends on which matplotlib backend you are using. Please see the following example for the 3 most common backends:

import matplotlib.pyplot as plt

plt.figure()
plt.plot([1,2], [1,2])

Option 1

QT backend

manager = plt.get_current_fig_manager()
# matplotlib3.3.4 work
manager.window.showMaximized()

Option 2

TkAgg backend

manager = plt.get_current_fig_manager()
# matplotlib3.2.1//2.2.3 work
manager.resize(*manager.window.maxsize())

报错:

AttributeError: 'MainWindow' object has no attribute 'maxsize'

Option 3–Ubuntu16.04不好使

WX backend

manager = plt.get_current_fig_manager()
manager.frame.Maximize(True)

报错:

AttributeError: 'FigureManagerQT' object has no attribute 'frame'

再加上下面显示图片和保存的;

plt.show()
plt.savefig('sampleFileName.png')

You can determine which backend you are using with the command matplotlib.get_backend(). When you save the maximized version of the figure it will save a larger image as desired.

自动显示和保存全屏-完整例程代码:

import matplotlib.pyplot as plt
plt.figure()
plt.plot([1,2], [1,2])

manager = plt.get_current_fig_manager()
manager.window.showMaximized()

plt.savefig('ep_reward.png',
			bbox_inches='tight',
			dpi=300,
			)

plt.show()

在这里插入图片描述

联系方式:

ps: 欢迎做强化的同学加群一起学习:

深度强化学习-DRL:799378128

欢迎关注知乎帐号:未入门的炼丹学徒

CSDN帐号:https://blog.csdn.net/hehedadaq

极简spinup+HER+PER代码实现:https://github.com/kaixindelele/DRLib

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hehedadaq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值