Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why matplotlib give the error [<matplotlib.lines.Line2D object at 0x0392A9D0>]?

Tags:

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?

like image 272
susansecret Avatar asked Sep 25 '15 03:09

susansecret


People also ask

What is Line2D?

public abstract class Line2D extends Object implements Shape, Cloneable. This Line2D represents a line segment in (x,y) coordinate space. This class, like all of the Java 2D API, uses a default coordinate system called user space in which the y-axis values increase downward and x-axis values increase to the right.

Why is %Matplotlib inline?

Why matplotlib inline is used. You can use the magic function %matplotlib inline to enable the inline plotting, where the plots/graphs will be displayed just below the cell where your plotting commands are written. It provides interactivity with the backend in the frontends like the jupyter notebook.

Is PLT show () necessary?

Plotting from an IPython shell Using plt. show() in Matplotlib mode is not required.

What is the difference between matplotlib Pyplot and matplotlib?

The matplotlib. pyplot is a collection of functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.


1 Answers

That isn't an error. That has created a plot object but you need to show the window. That's done using pyplot.show(). As stated in the comments, please do not use pylab, but use matplotlib.pyplot instead as pylab has been deprecated. As such, all you have to do is call:

plt.show() 

Just for reproducibility, here's a trace from the Python REPL (using IPython):

In [1]: import matplotlib.pyplot as plt  In [2]: plt.plot([1,2,3,4]) Out[2]: [<matplotlib.lines.Line2D at 0x123245290>]  In [3]: plt.show() 

We get:

enter image description here


What about in a Jupyter notebook?

If you are using this in a Jupyter notebook, instead of having to use show(), you can place the following in a separate cell after you import matplotlib.pyplot:

%matplotlib inline 

This will automatically draw the figure once you create it and you will not have to use show() after you're done.

like image 124
rayryeng Avatar answered Sep 28 '22 07:09

rayryeng