scatter_squares

import matplotlib.pyplot as plt

# Use scatter to draw a scatter plot and set its style

"""first_version"""
# Draw a single point-use sactter(), and pass xy-draw a point at the specified position
plt.scatter(2,4)

"""second_version"""
plt.scatter(2,4,s=200) # The actual parameter s sets the size of the points used when drawing the image

# Set the icon title and label the axis
plt.title("Square Numbres",fontsize=24)
plt.xlabel("Value",fontsize=14)
plt.ylabel("Square of Value",fontsize=14)

# Set the size of the tick mark
plt.tick_params(axis="both",labelsize=14)


"""third_version"""
x_values = [1,2,3,4,5]
y_values ​​= [1,4,9,16,25]

# Pass a list of values ​​to scatter
plt.scatter(x_values,y_values,s=100)


"""forth_version"""
x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]

plt.scatter(x_values,y_values,s=40)

plt.title("Square Numbers",fontsize=24)
plt.xlabel("Value",fontsize=14)
plt.ylabel("Square of Value",fontsize=14)

# Set the value range of each axis
plt.axis ([0,1100,0,1100000])

"""Delete the outline of the data point"""
# The default blue and black contours of the scatter chart. To delete the contours of the data points, specify the parameter edgecolors as none
x_values = [1,2,3]
y_values ​​= [1,4,9]

plt.scatter(x_values,y_values,edgecolors="none",s=40)

"""Custom colors"""
x_values = [1,2,3]
y_values ​​= [1,4,9]

# Pass parameter c to scatter, specified as the name of the color to be used
# plt.scatter(x_values,y_values,c="red",edgecolors="none",s=40)

# You can also use the rgb color mode to customize the color, pass the parameter c, and set it as a tuple, which contains three decimal values ​​between 0-1
# Represents the red, green and blue components respectively, the closer the value is to 0, the darker the specified color, the closer the value is to 1, the lighter the specified color
plt.scatter(x_values,y_values,c=(0,0,0.8),edgecolors="none",s=40)

"""Use color mapping"""
x_values = list(range(1001))
y_valuse = [x**2 for x in x_values]
# Color mapping is a series of colors, they are gradient from the start color to the end color. In visualization, color mapping is used to highlight the law of data
# pyplot has a set of built-in color maps. To use these color maps, you need to tell pyplot how to set the color of each point in the data set
plt.scatter(x_values,y_valuse,c=y_valuse,cmap=plt.cm.Blues,edgecolor="none",s=40)


"""Automatically save chart"""
# The first parameter is the name of the saved graph, and the second parameter specifies that the extra blank area of ​​the graph should be cropped. If you want to keep the surrounding blank, you can ignore this parameter
# plt .savefig("squares_plot.png",bbox_inches="tight")

# plt.show()

Guess you like

Origin blog.csdn.net/wyzworld/article/details/88245111