Close a figure - PyCharm(关闭图 - 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:关闭图 - PyCharm


基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01