This paper mainly introduces the implementation of the sinusoidal curve of Python graphics operation, involving Python using NumPy module numerical operation and Matplotlib.pyplot module for drawing the relevant operation skills, the need for friends can refer to, hope to help everyone.
To draw a sine curve, set the value range of x from 0 to 2 π first. To use the NumPy module.
numpy.pi denotes π
numpy.arange( 0 , 2π ,0.01)from 0 to 2 π, take 0.01 steps.
Make
X=numpy.arange (0, 2*numpy.pi, 0.01) y=numpy.sin (x)
Drawing uses the plot method in the matplotlib.pyplot module.
Plot (x, y) pyplot.plot.show ()
The complete code is as follows:
Import NumPy as Npimport Matplotlib.pyplot as Pltx=np.arange (0,2*np.pi,0.01) y=np.sin (x) plt.plot [x, Y] plt.show ()
This picture is a bit monotonous, you can add something to decorate it.
Plt.xlabel ("X-axis label")
Plt.ylabel ("Y-axis label")
Plt.title ("image title")
Plt.xlim (0,5) selects a graphic fragment within the X range in the drawing.
Plt.ylim (0,5) y fragment
Plt.plot (x,y,linewidth=4) Set the width of the line
Plt.plot (x, Y, "G") g represents the type of line that the character behind the green represents. such as dashed lines, dotted lines, etc.
{y: Yellow B: Black C: Gray defaults to Blue}
Character-type
Y1=sin (x) y2=cos (x)
You can draw two curves in the same diagram.
Plt.plot (X1,y1,x2,y2)