python+matplotlib+ drawing different icon types

Source: Internet
Author: User

#==================================================================
#首先需要导入两个文件
Import Matplotlib.pyplot as Plt
Import NumPy as NP
#==================================================================

1 #==================================================================2 #you need to import two of files first3 ImportMatplotlib.pyplot as Plt4 ImportNumPy as NP5 #==================================================================6 #draw a linear graph7x = Np.arange ( -2*np.pi,2*np.pi,0.01)#defining the horizontal axis range ( -2pi 2pi)8y = Np.sin (3*x)/x#function9y2 = Np.sin (2*x)/xTenY3 = Np.sin (x)/x OnePlt.plot (x, y)#draw, matplotlib show different colors by default APlt.plot (X,y2,'--') - Plt.plot (x,y3) -Plt.xticks ([ -2*np.pi,-np.pi,0,np.pi,2*np.pi],[r'$-2\pi$'R'$\pi$','$0$','$\pi$','$2\pi$'])#Displays the horizontal axis scale value without the second argument, which displays a numeric value instead of a letter thePlt.yticks ([ -1,0,1,2,3],[r'$-1$','$0$','$+1$','$+2$','$+3$']) -Plt.legend (['Y1','y2','Y3']) -Plt.title ('Neo-karl') -Plt.show ()

Operation Result:

1 #Move the axis to the middle, which is the Cartesian axis. 2 #Path: Hide the graph on the right, and move the bottom and left to the middle, using the GAC function to get the Axes object3 #This object is then used to specify the position of each edge, and the Set_color is set to none. The implementation code is as follows:4x = Np.arange ( -2*np.pi,2*np.pi,0.01)#defining the horizontal axis range5y = Np.sin (3*x)/x#function6y2 = Np.sin (2*x)/x7Y3 = Np.sin (x)/x8Plt.plot (x, y)#draw, matplotlib show different colors by default9Plt.plot (X,y2,'--')Ten Plt.plot (x,y3) OnePlt.xticks ([ -2*np.pi,-np.pi,0,np.pi,2*np.pi],[r'$-2\pi$'R'$\pi$','$0$','$\pi$','$2\pi$'])#Displays the horizontal axis scale value without the second argument, which displays a numeric value instead of a letter APlt.yticks ([ -1,0,1,2,3],[r'$-1$','$0$','$+1$','$+2$','$+3$']) -Plt.legend (['Y1','y2','Y3']) -Plt.title ('Neo-karl') theAx = PLT.GCA ()#get the Axes object using the GCA function -ax.spines[' Right'].set_color ('None')#Hide right side -ax.spines['Top'].set_color ('None') -Ax.xaxis.set_ticks_position ('Bottom')#set the bottom edge to the horizontal axis +ax.spines['Bottom'].set_position (('Data', 0))#Place coordinates at coordinates 0 -Ax.yaxis.set_ticks_position (' Left')#left set to ordinate +ax.spines[' Left'].set_position (('Data', 0)) APlt.show ()

Operation Result:

1x = Np.arange ( -2*np.pi,2*np.pi,0.01)#defining the horizontal axis range2y = Np.sin (3*x)/x#function3y2 = Np.sin (2*x)/x4Y3 = Np.sin (x)/x5Plt.plot (x, y)#draw, matplotlib show different colors by default6Plt.plot (X,y2,'--')7 Plt.plot (x,y3)8Plt.xticks ([ -2*np.pi,-np.pi,0,np.pi,2*np.pi],[r'$-2\pi$'R'$\pi$','$0$','$\pi$','$2\pi$'])#Displays the horizontal axis scale value without the second argument, which displays a numeric value instead of a letter9Plt.yticks ([ -1,0,1,2,3],[r'$-1$','$0$','$+1$','$+2$','$+3$'])TenPlt.legend (['Y1','y2','Y3']) OnePlt.title (' Neo-karl') A #To add a comment, using the annotate function, the first parameter is: Latex expression, which is the character to be realistic, XY is the position of the data point of the note in the chart, Xytext represents the distance between the comment and the data point, textcoords= ' offset points ' seems to be required? Using the Arrowprops control arrows -Plt.annotate (R'$\lim_{x\to 0}\frac{\sin (x)}{x}=1$', xy=[0,1],xytext=[30,30],fontsize=16,textcoords='Offset Points', Arrowprops=dict (arrowstyle=' -', connectionstyle='arc3,rad=.2')) -Ax = PLT.GCA ()#get the Axes object using the GCA function theax.spines[' Right'].set_color ('None')#Hide right side -ax.spines['Top'].set_color ('None') -Ax.xaxis.set_ticks_position ('Bottom')#set the bottom edge to the horizontal axis -ax.spines['Bottom'].set_position (('Data', 0))#Place coordinates at coordinates 0 +Ax.yaxis.set_ticks_position (' Left')#left set to ordinate -ax.spines[' Left'].set_position (('Data', 0)) +Plt.show ()

Operation Result:

python+matplotlib+ drawing different icon types

Related Article

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.