Analysis of Python's sine curve realization method

Source: Internet
Author: User
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)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.