No plot window in matplotlib

2019-01-08 07:47发布

I just installed matplotlib in Ubuntu 9.10 using the synaptic package system. However, when I try the following simple example

>>> from pylab import plot;
>>> plot([1,2,3],[1,2,3])
[<matplotlib.lines.Line2D object at 0x9aa78ec>]

I get no plot window. Any ideas on how to get the plot window to show?

10条回答
Viruses.
2楼-- · 2019-01-08 07:53

pylab.show() works but blocks (you need to close the window).

A much more convenient solution is to do pylab.ion() (interactive mode on) when you start: all (the pylab equivalents of) pyplot.* commands display their plot immediately. More information on the interactive mode can be found on the official web site.

I also second using the even more convenient ipython -pylab (--pylab, in newer versions), which allows you to skip the from … import … part (%pylab works, too, in newer IPython versions).

查看更多
We Are One
3楼-- · 2019-01-08 07:54

If you are starting IPython with the --pylab option, you shouldn't need to call show() or draw(). Try this:

ipython  --pylab=inline
查看更多
地球回转人心会变
4楼-- · 2019-01-08 07:55

Try this:

import matplotlib
matplotlib.use('TkAgg') 

BEFORE import pylab

查看更多
beautiful°
5楼-- · 2019-01-08 07:58

Any errors show up? This might an issue of not having set the backend. You can set it from the Python interpreter or from a config file (.matplotlib/matplotlibrc) in you home directory.

To set the backend in code you can do

import matplotlib
matplotlib.use('Agg')

where 'Agg' is the name of the backend. Which backends are present depend on your installation and OS.

http://matplotlib.sourceforge.net/faq/installing_faq.html#backends

http://matplotlib.org/users/customizing.html

查看更多
Animai°情兽
6楼-- · 2019-01-08 08:00

Modern IPython uses the "--matplotlib" argument with an optional backend parameter. It defaults to "auto", which is usually good enough on Mac and Windows. I haven't tested it on Ubuntu or any other Linux distribution, but I would expect it to work.

ipython --matplotlib
查看更多
对你真心纯属浪费
7楼-- · 2019-01-08 08:02

You can type

import pylab
pylab.show()

or better, use ipython -pylab.

查看更多
登录 后发表回答