【Spinning up】2.1、将Matplotlib自动全屏显示和保存图像(Saving Matplotlib graphs to image as full screen) 您所在的位置:网站首页 plt设置保存图片大小 【Spinning up】2.1、将Matplotlib自动全屏显示和保存图像(Saving Matplotlib graphs to image as full screen)

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

2024-07-09 23:48| 来源: 网络整理| 查看: 265

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



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有