plt.show () does not open a new figure window

17.9k Views Asked by At

I am trying to show some plots using plt.show (). i get the plots shown on the IPython console, but I need to see each figure in a new window. What can I do ?

3

There are 3 best solutions below

0
On BEST ANSWER

You want to type %matplotlib qt into your iPython console. This changes it for the session you're in only. To change it for the future, go Tools > Preferences, select iPython Console > Graphics, then set Graphics Backend to Qt4 or Qt5. This ought to work.

0
On

Other option is using plt.figure:

import matplotlib.pyplot as plt
plt.figure(1)                # the first figure
plt.subplot(211)             # the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212)             # the second subplot in the first figure
plt.plot([4, 5, 6])
plt.show(block=False)

plt.figure(2)                # a second figure
plt.plot([4, 5, 6])          # creates a subplot(111) by default
plt.show(block=False)

plt.figure(1)                # figure 1 current; subplot(212) still current
plt.subplot(211)             # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title
plt.show(block=False)

(see: https://matplotlib.org/users/pyplot_tutorial.html)

0
On

In your notebook, try

    import matplotlib.pyplot as plt
    %matplotlib

Called alone like this, it should give output in a separate window. There are also several options to %matplotlib depending on your system. To see all options available to you, use

    %matplotlib -l

Calling

    %matplotlib inline

will draw the plots in the notebook again.