8

This must be a really basic question: I am trying to use Matplotlib. Here's the basic example from the documentation.

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,5,0.1)
y = np.sin(x)
plt.plot(x,y)

I have tried this in ipython, bpython and the default interpreter (Ubuntu 10.10, 64 bit) and all I get are messages like:

[<matplotlib.lines.Line2D object at 0x3f14a90>]

What am I doing wrong?

2 Answers 2

15

You're missing plt.show() to order matplotlib to show a window with the graph.

Sign up to request clarification or add additional context in comments.

3 Comments

or plt.savefig to save the result in an image file
OMG, for some annoying reason when running Spyder I never needed this, but I didn't understand why Eclipse didn't show my plots...
Ivo: Because spyder starts mpl in ion() mode.
6

In its default configuration, matplotlib needs to be told to render. That's what plt.show() does.

Matplotlib also has an interactive mode that can be useful when you're working interactively and want your plotting commands to happen immediately. The easiest way to use this is by opening an ipython session with the -pylab option. http://matplotlib.sourceforge.net/users/shell.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.