"Python" uses scatter () to plot a scatter plot.

Source: Internet
Author: User

Plot a simple scatter plot

To draw a single point, use the scatter () function and pass a pair of x and Y coordinates to it, which draws a point at the specified position

Import Matplotlib.pyplot as Pltplt.scatter (2,4) plt.show ()

Operation Result:

Graphic Landscaping

The following sets the output style to make it more interesting: add headings, label axes

ImportMatplotlib.pyplot as Pltplt.scatter (2,4,s=200)#set the title and add axis labelsPlt.title ("Squares Numbers", fontsize=24) Plt.xlabel ("Value", fontsize=14) Plt.xlabel ("Square of Value", fontsize=14)#set the size of the tick markPlt.tick_params (axis='both', which='Major', labelsize=14) plt.show ()

Operation Result:

Draw a series of scatter points

To draw a series of scatter points, pass a list of 2 x and Y values to scatter ()

The coordinates plotted were (2,4), (3,9), (4,16), (5,25)

Automatically generate data plot scatter plots
ImportMatplotlib.pyplot as Pltx= List (range (1,1001)) Y= [x**2 forXinchX]plt.scatter (X,y,s=200)#set the title and add axis labelsPlt.title ("Squares Numbers", fontsize=24) Plt.xlabel ("Value", fontsize=14) Plt.xlabel ("Square of Value", fontsize=14)#set the size of the tick markPlt.tick_params (axis='both', which='Major', labelsize=14)#set the range of values for each coordinatePlt.axis ([0,1100,0,1100000]) plt.show ()

Operation Result:

Delete the outline of a data point

As can be seen, when drawing many points, the contour will be joined together, to delete the contour of the data point can call scatter (), pass argument edgecolor= ' None '

Custom Colors

To modify a color, simply pass the parameter C to scatter () and set it to the name of the color you want to use

Operation Result:

Using color maps

Module Pyplot has a set of color mappings built in to use these color mappings, you need to tell Pyplot how to set the color of each point in the dataset

Operation Result:

Auto-Save Scatter plots

Do I need to save the scatter plot automatically after the above graphic is finished? If necessary, proceed as follows:

Note: You must note the Plt.show () code when you save the graphic, otherwise the graphic is blank after the save is complete

After clicking Run, you can see that the picture is saved in the directory where the program is located.

First argument: Specifies the saved picture name

Second argument: Cuts out the specified white space

"Python" uses scatter () to plot a scatter plot.

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.