Python visual scatter plot. Histogram, Contour

Source: Internet
Author: User

Scatter chart

ImportMatplotlib.pyplot as PltImportNumPy as NP#N pointsn = 1024#The average is 0, and the variance is 1.X = Np.random.normal (0,1, N) Y= Np.random.normal (0,1, N)#Determine colorT =np.arctan2 (y,x) plt.scatter (x,y,s=75,c=t,alpha=0.5)#Plt.scatter (Np.arange (5), Np.arange (5))Plt.xlim (-1.5,1.5) Plt.ylim (-1.5,1.5)#Hide all the ticksPlt.xticks (()) Plt.yticks (()) plt.show ()

Bar chart:

ImportMatplotlib.pyplot as PltImportNumPy as NP#12 Bar ChartsN=12X= Np.arange (n)#X will generate 0 to oneY1 = (1-x/float (n)) *np.random.uniform (0.5, 1.0, N)#randomly randomly generate numbers from 0.5 to 1Y2 = (1-x/float (n)) *np.random.uniform (0.5, 1.0, N) plt.bar (X,+y1,facecolor='#9999ff', edgecolor=' White') Plt.bar (X,-y2,facecolor='#ff9999', edgecolor=' White')#zip is to give the values in X,y1 to X and Y, respectively.#Plt.text (x position, y position, value) forX, yinchZip (x,y1):#ha:horizontal Alignment AlignmentPlt.text (x,y+0.05,'%.2f'% y,ha='Center', va='Bottom')     forX, yinchZip (x,y2):#ha:horizontal Alignment AlignmentPlt.text (x,-y-0.05,'-%.2f'% y,ha='Center', va='Top') Plt.xlim (-.5, N) plt.xticks (()) Plt.ylim (-1.25,1.25) Plt.yticks (()) plt.show ()

Contour

ImportMatplotlib.pyplot as PltImportNumPy as NP#calculate height by x, ydeff (x, y):return(1-x/2+x**5+y**3) *np.exp (-x**2-y**2) n=256x=np.linspace ( -3,3, N) y=np.linspace ( -3,3, N)#bind x, y to the input values of the gridX, y =Np.meshgrid (x, y)#Use plt.contourf to filling contours#x, Y and value for (x, y) point#Contour for Grids#8 delegates divided into 10 sections#0 divided into 2 sections#Plt.cm.cool for cold tones, plt.cm.hot for warm tones, Plt.cm.spectral,plt.cm.hsv,plt.cm.oceanPlt.contourf (x,y,f (x, y), 8,ALPHA=0.75,CMAP=PLT.CM.HSV)#Paint the Color#Use plt.contour to add Contounlines#draw lines, contour lines for contoursC = Plt.contour (x,y,f (x, y), 8,colors='Black', linwidth=.5)#adding labelPlt.clabel (c,inline=true,fontsize=10) Plt.xticks (()) Plt.yticks (()) plt.show ()

This knowledge is learned in the mo bored python

Python visual scatter plot. Histogram, Contour

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.