Thorn Thorn - 3 months ago 21
Python Question

matplotlib does not show my drawings although I call pyplot.show()

I need your help about matplotlib. Yes, I did not forget calling the pyplot.show().

$ ipython --pylab



import matplotlib.pyplot as p
p.plot(range(20), range(20))


It returns
matplotlib.lines.Line2D at 0xade2b2c
as the output.

p.show()


There is nothing to happen. No error message. No new window. Nothing. I install
matplotlib
by using pip and I didn't take any error messages.

Details:

I use,


  • Ubuntu

  • IPython v0.11

  • Python v2.6.6

  • matplotlib v1.0.1


Answer

If I set my backend to template in ~/.matplotlib/matplotlibrc, then I can reproduce your symptoms:

~/.matplotlib/matplotlibrc:

# backend      : GtkAgg
backend      : template

Note that the file matplotlibrc may not be in directory ~/.matplotlib/. In this case, the following code shows where it is:

>>> import matplotlib
>>> matplotlib.matplotlib_fname()

In [1]: import matplotlib.pyplot as p

In [2]: p.plot(range(20),range(20))
Out[2]: [<matplotlib.lines.Line2D object at 0xa64932c>]

In [3]: p.show()

If you edit ~/.matplotlib/matplotlibrc and change the backend to something like GtkAgg, you should see a plot. You can list all the backends available on your machine with

import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)

It should return a list like:

['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg',
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf',
'ps', 'svg', 'template']

Reference:

Comments