0

I am using pandas builtin plotting as per below. However as soon as the plotting method returns, the plot disappears. How can I keep the plot(s) open until I click on them to close?

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

def plot_data():
    #...create dataframe df1
    pd.options.display.mpl_style = 'default'
    df1.boxplot()
    df1.hist()

if __name__ == '__main__':
    plot_data()
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
Don Smythe
  • 9,234
  • 14
  • 62
  • 105

1 Answers1

2

Use a plt.show(block=True) command to keep the plotting windows open.

[...]
df1.boxplot()
df1.hist()
plt.show(block=True)

In my version of matplotlib (1.4.3), block=True is necessary, but that may not be the case for all versions (Keep plotting window open in Matplotlib)

Community
  • 1
  • 1
bernie
  • 546
  • 3
  • 13