1

I have created subplots on entire pandas dataframe df using following

plots = df.plot(subplot=True, layout=(2,3))

After this I do get the plot in separate window in Spyder. However,if I close this window and want to display plots again, I am not able to do it. plots.show() does not work since plots is created as numpy array. I looked into two other similar posts, but can't figure it out. 1. Matplotlib: how to show plot again? 2. matplotlib show figure again

Grr
  • 15,553
  • 7
  • 65
  • 85
r_hudson
  • 193
  • 8
  • 2
    I think you can set the preference in Tools-->Preferences-->IPython console-->Graphics tab but I think you would need to re-start Spyder for the changes to take place – Nev1111 May 06 '19 at 14:08
  • @Nev1111 : Since it involves restarting, I will have to try it later and let you know if it worked. Thanks. – r_hudson May 06 '19 at 14:31

1 Answers1

2

Create a separate figure and axes object and pass the axes to pandas.plot. This allows you to keep the figure open without blocking your code. I like this because I can update the figure and use fig.canvas.draw followed by fig.show to show updates.

import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame({x: range(5) for x in 'abcdef'})
fig, ax = plt.subplots()
df.plot(ax=ax, subplots=True, layout=(2,3))
fig.show()

enter image description here

Then if you close the figure window you can bring it back with another call to fig.show. You can also modify an individual subplot like I mentioned earlier.

plots[0,0].axhline(3)
fig.canvas.draw()
fig.show()

enter image description here

Grr
  • 15,553
  • 7
  • 65
  • 85