1

I am trying to display only a specific figure from a list of figures I created. Unfortunately, fig.show() will open a windows which closes immediately. I am using python 3.8 and the pycharm IDE on windows 7 :

import matplotlib.pylab as plt
import numpy as np

def sinewave(A, omega):
    fig = plt.figure()
    t = np.linspace(0, 10, 25)
    y = A * np.sin(omega * t)
    plt.plot(y, t)
    return fig

A = 1
omega = np.linspace(10,35,10)
fig_list = []

for i in range(len(omega)):
    fig_list.append(sinewave(A, omega[i]))

fig_list[3].show() # should do the trick but open a window which shuts down immediately !

How should I do things correctly ?

Anon_Chem
  • 11
  • 1
  • Try removing `.show()`. `fig_list[3]` works for me in a Jupyter notebook. – Fourier Feb 12 '20 at 17:15
  • You would need to close all other figures, except the one that you want to show. – ImportanceOfBeingErnest Feb 12 '20 at 17:16
  • To ImportanceOfBeingErnest : However I don't want to close all figures since I don't know in advance which one I will show. For simplicity, consider that I want to show figure 5, and then figure 3. To Fourier: This does not work for me in a Jupyter notebook either : it displays all the figures. – Anon_Chem Feb 13 '20 at 09:37
  • (Use *@username*, not *to username* to notify someone - read through the [help]) Reopening closed figures is not currently implemented, however see https://stackoverflow.com/questions/31729948/matplotlib-how-to-show-a-figure-that-has-been-closed for workarounds. – ImportanceOfBeingErnest Feb 13 '20 at 11:21

0 Answers0