3

I've read these and tried the solutions but still not getting anything to show:

matplotlib show nothing although i called show

Why doesn't pyplot.show() work? [duplicate]

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

I'm using Python 2.7.6 |Anaconda 1.9.0 (64-bit) on Ubuntu 12.04. How can I go about diagnosing the problem and trying to solve it?

EDIT:

-First I edited matplotlibrc and change the backend to GtkAgg (was set to QtAgg).

-Then I tried to change the backend via code: matplotlib.rcParams['backend'] = "GtkAgg"

EDIT2 - adding detail from the Spyder console (no plot is shown at the end):

Python 2.7.6 |Anaconda 1.9.0 (64-bit)| (default, Jan 17 2014, 10:13:17) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.8.0, SciPy 0.13.3, Matplotlib 1.3.1
Type "scientific" for more details.
>>> scientific

This is a standard Python interpreter with preloaded tools for scientific 
computing and visualization. It tries to import the following modules:

>>> import numpy as np  # NumPy (multidimensional arrays, linear algebra, ...)
>>> import scipy as sp  # SciPy (signal and image processing library)
>>> import matplotlib as mpl         # Matplotlib (2D/3D plotting library)
>>> import matplotlib.pyplot as plt  # Matplotlib's pyplot: MATLAB-like syntax
>>> from pylab import *              # Matplotlib's pylab interface
>>> ion()                            # Turned on Matplotlib's interactive mode

Within Spyder, this interpreter also provides:
    * special commands (e.g. %ls, %pwd, %clear)
    * system commands, i.e. all commands starting with '!' are subprocessed
      (e.g. !dir on Windows or !ls on Linux, and so on)

>>> plot(range(3))
[<matplotlib.lines.Line2D object at 0x3f3cd50>]
>>> show()
Community
  • 1
  • 1
ADJ
  • 3,902
  • 7
  • 39
  • 76

3 Answers3

2

In order for your matplotlib backend choice to work, you need to have the Python bindings for that backend installed. You may be running a GTK-based windows manager like GNOME, for example, but still not have the Python bindings around. According to this, the proper Ubuntu package is python-gtk. So, open up your favorite Terminal emulator and enter

sudo apt-get install python-gtk

(you'll need admin privileges to do it). Restart your python/matplotlib session, and you should be good to go.

MattDMo
  • 90,104
  • 20
  • 213
  • 210
  • I get this error when I run that code in terminal: Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package python-gtk – ADJ May 26 '14 at 19:23
2

I ended up solving by doing this in Spyder: Preferences -> Console -> External modules -> check Install Spyder's input hook for Qt

ADJ
  • 3,902
  • 7
  • 39
  • 76
0

I'm on Mavericks, solved the problem by changing backend to Qt4Agg in matplotlibrc. (as instructed in another answer here: Why doesn't pyplot.show() work?)

Community
  • 1
  • 1
7inyu
  • 1