关闭图 - PyCharm [英] Close a figure - PyCharm

查看:45
本文介绍了关闭图 - PyCharm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一个多小时搜索,只是为了弄清楚这个简单的事情.因此,在考虑这是一个重复的问题之前,请将我的问题与那里的任何问题进行比较.

I have spent over an hour searching, just to figure this simple thing. So, before considering this a duplicate question, please compare my question to any question out there.

这是我的代码:

import pandas
import matplotlib.pyplot as plt

dataset = pandas.read_csv('international-airline-passengers.csv', usecols=[1], engine='python', skipfooter=1)
print dataset, type(dataset)
plt.plot(dataset)
plt.show()
plt.close()

首先,我理解的 plt.show() 是一个阻塞函数.那么关闭图的方法是什么.在它之后写 plt.close() 是没有意义的.那么正确的放置方式在哪里.

Firstly, plt.show() to my understanding is a blocking function. So what is the way to close the figure. There is no point in writing plt.close() after it. So where is the right way to put it.

其次,当我执行相同 python 代码的新进程时,如何确保所有窗口都关闭.例如,在 MATLAB 中,可以很容易地在文件的开头说 close all 并关闭所有打开的绘图,这些绘图是先前 MATLAB 代码执行的结果.plt.close('all') 也不起作用.

Secondly, how can I make sure all the windows are closed when I execute a new process of the same python code. For example in MATLAB, one could easily say close all in the beginning of their file and it closes all the opened plots which were the result of previous MATLAB code execution. plt.close('all') is not working either.

我正在使用 PyCharm.我在第一种情况下发现的结果可能适用于 IDLE,但不适用于 PyCharm.我该怎么做 PyCharm.

I am using PyCharm. The results I found for the first situation, might work on IDLE but not in the PyCharm. How can I do it PyCharm.

推荐答案

plt.show(block=False) 可以解决问题 - 这是您可以使此函数非阻塞的方法(都处于运行和调试模式).主要缺点是如果代码结束,图形会自动关闭...

plt.show(block=False) will do the trick- This is the way you can make this function non-blocking (both in run & debug mode). The main dis-advantage is that if the code ends, the figure is automatically closes...

这篇关于关闭图 - PyCharm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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