pandas 如何关闭熊猫数据框图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27927957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:50:30  来源:igfitidea点击:

how to close pandas dataframe plot

pythonpandasplot

提问by anonygrits

This feels like (and probably is) a really dumb question, but what do you call to close a dataframe plot that didn't explicitly call matplotlib?

这感觉就像(并且可能是)一个非常愚蠢的问题,但是您调用什么来关闭未明确调用 matplotlib 的数据框图?

for example, if you type:

例如,如果您键入:

df.hist(data)

Is there a way to close the plot (other than manually clicking on the window's x)?

有没有办法关闭绘图(除了手动单击窗口的 x)?

I'm used to calling plt.close(), but is there something similar in pandas? I've tried close & close(), and neither work.

我习惯于调用 plt.close(),但是在 Pandas 中有类似的东西吗?我尝试过关闭和关闭(),但都不起作用。

回答by elyase

This will wait 5 seconds before closing the window:

这将在关闭窗口前等待 5 秒钟:

import matplotlib.pyplot as plt
import pandas as pd
import time

ax = df.plot()
fig = ax.get_figure()
plt.show(block=False)
time.sleep(5)
plt.close(fig)

Alternatively:

或者:

fig, ax = plt.subplots()
df = pd.Series([1, 2, 3])
df.plot(ax=ax)
plt.show(block=False)
time.sleep(5)
plt.close(fig)