First install matplotlib, use pip install Matplotlib. After the installation is completed, in the command line of Python, import matplotlib, if no problem, the installation can start drawing.
Watch the moment, witness the miracle.
from Import Pyplot as Pltplt.plot ([1,2,3,4,5],[4,3,4,3,4]) # paint plt.show on canvas () # Show Canvas
Draw the line, need to give the coordinates of the point on the outlet, then Matplotlib will automatically connect the point to the line. We see that the coordinates of the two points are list, but preferably an array of numpy, because the matrix can be operated directly.
Import# generates 1-10 of 20 points Plt.plot (x, x**3) plt.show ()
x = Range (8)
Plt.plot (x, [i**3 for I in X])
Plt.show ()
You can see that the dots in the numpy array make the image smoother and finer points.
I'm a lazy guy, let me merge two graphs.
Import= numpy.linspace (1,10,20) plt.plot (x, X for in Range (0,8,3)]) Plt.show ()
Always draw such a line does not feel monotonous, below let us change the style of rerouting
First, color
The correspondence between colors is
b---blue c---cyan g---green k----black
M---magenta r---red w---white y----yellow
Import= numpy.linspace (1,10,20) plt.plot (x, x'g' for inch ' R ' # The third parameter is the color plt.show ()
Second, line
-Solid Line
--Short
-. Short point and alternating line
: Virtual Dot Line
Import= numpy.linspace (1,10,20) plt.plot (x, x'g--' for inch ' R. ' ) plt.show ()
Three, the style of the point
. point marker
, pixel marker
o circle marker
V triangle Down marker ,
^ triangle up marker ,
< triangle left marker
> triangle right marker ,
1 tripod down marker
2 tripod up marker
3 tripod left marker
4 tripod right marker
S square marker
p Pentagon marker
* star marker
H hexagon marker
h rotated Hexagon D Diamond Marker
D thin Diamond Marker
| Vertical Line (vlinesymbol) marker
_ horizontal Line (hline symbol) marker
+ plus Marker
X cross (x) marker
Import= numpy.linspace (1,10,20) plt.plot (x, x'gx--' for inch ' rs-. ' ) plt.show ()
Drawing is here, summing up, drawing as long as 3 steps, 1. Load Package 2. Draw the point onto the canvas 3. Display the canvas. And the style of the line, color and the type of point can be modified according to the situation.
matplotlib--first chapter easy to draw a picture