I am new user of matplotlib, my platform is Ubuntu 10.04 Python 2.6.5
This is my code
import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt plt.plot([1,2,3])
The error is:
/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py:41: UserWarning: Your currently selected backend, 'agg' does not support show(). Please select a GUI backend in your matplotlibrc file ('/usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data/matplotlibrc') or with matplotlib.use() (backend, matplotlib.matplotlib_fname()))
apt-get install libagg
but it is doesn't work.python-gtk2-dev
package, but still the error is below.Here is the error:
>>> matplotlib.use('GTK') >>> import matplotlib.pyplot as plt Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.6/dist-packages/matplotlib/pyplot.py", line 95, in <module> new_figure_manager, draw_if_interactive, show = pylab_setup() File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup globals(),locals(),[backend_name]) File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_gtk.py", line 28, in <module> from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_gdk.py", line 29, in <module> from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array ImportError: No module named _backend_gdk
In modern matplotlib there is no "default backend", i.e. the rcParams['backend'] is set to a "sentinel". Upon importing matplotlib the first working backend from a candidate list ["macosx", "qt5agg", "qt4agg", "gtk3agg", "tkagg", "wxagg"] is chosen.
%matplotlib inline sets the backend of matplotlib to the 'inline' backend: With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.
With the TkAgg backend, which uses the Tkinter user interface toolkit, you can use matplotlib from an arbitrary non-gui python shell. Just set your backend : TkAgg and interactive : True in your matplotlibrc file (see Customizing matplotlib) and fire up python.
Your currently selected backend, 'agg' does not support show().
AGG
backend is for writing to file, not for rendering in a window. See the backend FAQ at the matplotlib web site.
ImportError: No module named _backend_gdk
For the second error, maybe your matplotlib distribution is not compiled with GTK support, or you miss the PyGTK package. Try to install it.
Do you call the show()
method inside a terminal or application that has access to a graphical environment?
Try other GUI backends, in this order:
TkAgg
wxAgg
Qt5Agg
Qt4Agg
FYI, I found I needed to put matplotlib.use('Agg')
first in Python import order. For what I was doing (unit testing needed to be headless) that meant putting
import matplotlib matplotlib.use('Agg')
at the top of my master test script. I didn't have to touch any other files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With