本文介绍了结束人物-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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 05:40