The functionality that Pyplot implements is similar to how it is plotted in MATLAB.
Let's look at an example of drawing a polyline:
Import Matplotlib.pyplot as Pltplt.plot ([1, 8, 9]) Plt.ylabel ("some Numbers") Plt.show ()
It can be found that since we have only given a one-dimensional array, the plot function treats the array index as the horizontal axis, and by default it connects all the points together in a straight line.
The horizontal axis can be complete as follows:
Plt.plot ([2, 3, 4, 5],[1, X, 8, 9]) #第一个参数指定了横轴的坐标, the second parameter specifies a vertical axis.
The drawing output is as follows:
Two questions were found, whether horizontal or vertical, the coordinate range is always determined by the minimum and maximum values in the array (such as the middle axis 2 to 5, the longitudinal axis 1 through 17). and is it possible to not connect these discrete points together?
The answer is yes, see the following code:
Import Matplotlib.pyplot as Pltplt.plot ([1, 2, 3, 4], [1,4,9, +], ' ro ') Plt.axis ([0, 6, 0,]) plt.show ()
The above code in the plot function set the third parameter, that is, the format string, which is almost completely copy of Matlab, ' ro ' r refers to Red, O-only circle shape, to draw the same line chart as before, the parameter is '-'.
It can also be found that the horizontal and vertical axes have become our designated range.
Finally, Pyplot also supports the drawing of multiple sets of data into a single picture.
Import NumPy as Npimport matplotlib.pyplot as Pltt = Np.arange (0., 5., 0.2) Plt.plot (t,t, ' r--', T, T**2, ' BS ', T, T**3, ' g ^ ') plt.show ()
The above is the basic content of Pyplot, with these, we can complete some basic drawing operations.
Pyplot Basic Drawing