Python matplotlib Drawing

Source: Internet
Author: User

ImportNumPy as NPImportMatplotlib.pyplot as Plt fromScipy.constants.constantsImportAlpha fromMatplotlib.patchesImportArrowstylex=np.linspace (-np.pi,np.pi,256,endpoint=True)#Np.linspace defines the horizontal axis, with a total of 256 points between-pi and Pi, endpoint=true means including the last pointc,s=Np.sin (x), Np.cos (x) plt.figure (1)#Generate a picturePlt.plot (x,c,color="Blue", linewidth=1.0,linestyle="-", label="COS", alpha=0.5)#alpha=0.5 TransparencyPlt.plot (X,s,"r*", label="Sin") Plt.title ("Sin")#Add titleAX=PLT.GCA ()#Axis Editor#spines refers to the top and bottom four tick marks in the graphax.spines[" Right"].set_color ("None")#hide the right tick mark Set_color to noneax.spines["Top"].set_color ("None")#hide the top tick lineax.spines[" Left"].set_position (("Data", 0))#Place the left tick mark to display the y-axis at scale 0 of the data fieldax.spines["Bottom"].set_position (("Data", 0))#Place the left tick mark at scale 0 on the data field to display the x-axisAx.xaxis.set_ticks_position ("Bottom")#The scale value of the horizontal axis is placed below the horizontal axis .Ax.yaxis.set_ticks_position (" Left")#The scale value of the ordinate is placed on the left side of the vertical axisPlt.xticks ([-np.pi,-np.pi/2,0,np.pi/2,np.pi],["1","2","3","4","5",])#change the original scale value to [1,2,3,4,5] display formPlt.yticks (Np.linspace ( -1, 1, 5, endpoint=true))#from 1 to 1, Mark 5 points, endpoint=true last point display forLabelinchAx.get_xticklabels () +ax.get_yticklabels ():#ax.get_xticklabels () Get Horizontal label ax.get_yticklabels () get the vertical axis labelLabel.set_fontsize (16)#set the font size for a labelLabel.set_bbox (Dict (facecolor="Red", edgecolor="None", alpha=0.2))    #set Label box facecolor to box fill color edgecolor to Border color alpha for transparencyLabel.set_rotation (90)#label rotation 90 degreesPlt.legend ()#Show Plt.plot in the label display legendPlt.legend (loc="Upper Left")#Show Plt.plot in label show Legend on top leftPlt.grid ()#Display grid linesPlt.axis ([ -1,1,-0.5,1])#Show the display range of a graphicPlt.fill_between (X,np.abs (x) <0.5,c,c>0.5,color="Green", alpha=0.25)#fill_between Fill Color gives a range of fills in the drawingT=1#Add a note to a t=1 placePlt.plot ([T,t],[0,np.cos (t)],"y", linewidth=3,linestyle="--")#"Y" is yellow#Plt.annotate ("cos (1)", xy= (T,np.cos (t)), xycoords="Data", xytext= (+10,+30), Textcoords="Offset Points", Arrowprops=dict (arrowstyle=" -", connectionstyle="arc3,rad=.2"))#cos (1) Note shows the location of the XY annotation xycoords defined as the offset increased by the data field Xytext#textcoords Specifies that the annotation is relative to the position of the Arrowstyle arrow, connectionstyle the Radian value of the arrowPlt.show ()#Show Graph

Python matplotlib Drawing

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.