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?
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 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.
Plotting from an IPython shell Using plt. show() in Matplotlib mode is not required.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With