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!

8
  • 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. Commented Oct 30, 2013 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. Commented Oct 30, 2013 at 21:16
  • 2
    Also <pet peeve> don't ever use import *. Just do import pylab and always prefix any pylab-specific entities with pylab.<entity_name>. 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) </pet peeve> Commented Oct 30, 2013 at 21:18
  • Works for me on Ubuntu 13.10 in terminal. Did you look at this answer? Commented Oct 30, 2013 at 21:20
  • 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? Commented Oct 31, 2013 at 1:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.