How to close pandas data graph

It looks like (and probably is) a really dumb question, but what are you calling to close a data plot that matplotlib did not explicitly call?

for example if you type:

df.hist(data)

      

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

I am using the plt.close () call, but is there something similar in pandas? I tried close and close () and it doesn't work.

+3


source to share


1 answer


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)

      



As an alternative:

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

      

+5


source







All Articles