1

I found this example for a simple plot on http://www.loria.fr/~rougier/teaching/matplotlib/#simple-plot:

from pylab import *

X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)

plot(X,C)
plot(X,S)

show()

But then absolutely nothing happens. No errors, no warnings, just nothing. Same thing whether it be in the terminal or in Eclipse. I'm using Python 2. Am I missing something?

Thanks!

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
marc
  • 2,037
  • 9
  • 24
  • 32
  • 2
    This code works fine for me with all basic installs of NumPy, matplotlib, etc., on Ubuntu 12.04 with Python 2.7.3. It works in the regular interpreter, from Eclipse, and from IPython. What OS are you using? Do you need to alter a DISPLAY environment variable or something? Maybe editing to give all details (versions of installs, OS version, display set up, etc.) will help. – ely Oct 30 '13 at 21:14
  • As a quick-fix attempt, try adding `ion()` right after the `import` line (this is `pylab`'s interactive plotting command). If it's a display or environment issue, this probably won't help, but it's worth a try. – ely Oct 30 '13 at 21:16
  • 2
    Also don't ever use `import *`. Just do `import pylab` and always prefix any `pylab`-specific entities with `pylab.`. The extra typing of `pylab` everywhere is awesome! It helps others know where a function came from when they read the code later, and you also don't have to worry about whether a function from `pylab` happens to have the same name as some other globally-imported function (and this happens *all the time* with the word `plot` because lots of people like to make functions called `plot` for their classes) – ely Oct 30 '13 at 21:18
  • Works for me on Ubuntu 13.10 in terminal. Did you look at [this answer](http://stackoverflow.com/a/14559772/1362167)? – LeartS Oct 30 '13 at 21:20
  • @EMS:not sure what a display environment is... – marc Oct 30 '13 at 21:50
  • @LeartS: that person was definitely having the same issue as me but the answer isn't very clear to me. – marc Oct 30 '13 at 21:53
  • @marc the backend determines how and where to display the plot. Some backends open a new window (which is what you want), while some print to file, image, etc. You have to check what your backend is (exec the command given in that answer) – LeartS Oct 30 '13 at 21:56
  • 1
    This is because your matplotlib build wasn't built with an interactive backend. If you were to save the plot, it will still work, there's just not an interactive gui option available. This happens when matplotlib either a) can't find the Tk (or qt/gtk/wx) libraries and header files or b) it's explicitly configured not to build any interactive backends (useful for servers, etc). How did you install matplotlib? If you built it from source, to you have Tk installed? – Joe Kington Oct 31 '13 at 01:21

0 Answers0