Matplotlib show () method does not open window

I use mac, and when I do the following with matplotlib:

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import pylab as P

...
plt.plot(x,y)  
plt.show() <-- nothing happens
plt.savefig('figure.png') <-- works fine

So, plt.showdoes not open a window or anything while plt.savefigworking fine.

What could be the problem?

+3
source share
1 answer

Pyplot will only display the shape window if

matplotlib.rcParams['interactive'] == True

This is so if you:

  • previous called plt.ion()in script or
  • equivalently called matplotlib.interactive(True), or
  • started an ipython session with an option --pylabon the command line.

, plt.show() , . , , ( ).


( , ):

plt.show() , . plt.get_backend() - 'agg', , .

,

import matplotlib
matplotlib.use('MacOSX')

script . matplotlib.

, , matplotlib rcfile. , matplotlib.matplotlib_fname().

+7

All Articles