如何关闭 pandas 数据框图 [英] how to close pandas dataframe plot

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

问题描述

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

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?

例如,如果您输入:

df.hist(data)

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

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

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

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

推荐答案

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

This will wait 5 seconds before closing the window:

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)

或者:

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

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

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