20
votes

I am using python 2.7.9 on win8. When I tried to plot using matplotlib, the following error showed up:

from pylab import *
plot([1,2,3,4])

[matplotlib.lines.Line2D object at 0x0392A9D0]

I tried the test code "python simple_plot.py --verbose-helpful", and the following warning showed up:

$HOME=C:\Users\XX matplotlib data path C:\Python27\lib\site-packages\matplotlib\mpl-data


You have the following UNSUPPORTED LaTeX preamble customizations:

Please do not ask for support with these customizations active.


loaded rc file C:\Python27\lib\site-packages\matplotlib\mpl-data\matplotlibrc matplotlib version 1.4.3 verbose.level helpful interactive is False platform is win32 CACHEDIR=C:\Users\XX.matplotlib Using fontManager instance from C:\Users\XX.matplotlib\fontList.cache backend TkAgg version 8.5 findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium to Bitstream Vera Sans (u'C:\Python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf') with score of 0.000000

What does this mean? How could I get matplotlib working?

7

7 Answers

33
votes

That isn't an error. That has created a plot object but you need to show the window. That's done using pyplot.show()... so you seriously just have to do...

show()

If you don't believe me, here's a trace from IPython:

In [9]: from pylab import *

In [10]: plot([1,2,3,4])
Out[10]: [<matplotlib.lines.Line2D at 0x123245290>]

In [11]: show()

We get:

enter image description here


As mentioned in the comments, you should avoid using pylab. You should use matplotlib.pyplot instead.... so:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
1
votes

In Jupyter nodebook, you could just insert

%matplotlib inline

before you use matplotlib.

0
votes

Incase you're using jupyter notebook, you can run interactive plotting on command

ion()

before you plot anything. This will show the graph in notebook itself.

0
votes

I came across this same message in jupyter notebook.

I just added %matplotlib notebook and my charts show up now.

I think %matplotlib inline should work also.

0
votes

Had this problem. You just have to use show() function to show it in a window. Use pyplot.show()

0
votes

When you run plt.plot() on Spider, you will now receive the following notification:

Figures now render in the Plots pane by default. To make them also appear inline in the Console, uncheck "Mute Inline Plotting" under the Plots pane options menu.

I followed this instruction, and it works.

-1
votes

You can also add plt.figure() before you plot, that will create a figure and plot your data on it