When Python uses matplotlib to draw a point map, the scatter parameters are explained in detail

1. Source code

@_copy_docstring_and_deprecators(Axes.scatter)
def scatter(
        x, y, s=None, c=None, marker=None, cmap=None, norm=None,
        vmin=None, vmax=None, alpha=None, linewidths=None,
        verts=cbook.deprecation._deprecated_parameter,
        edgecolors=None, *, plotnonfinite=False, data=None, **kwargs):
    __ret = gca().scatter(
        x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
        vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,
        verts=verts, edgecolors=edgecolors,
        plotnonfinite=plotnonfinite,
        **({
    
    "data": data} if data is not None else {
    
    }), **kwargs)
    sci(__ret)
    return __ret

2. Detailed explanation of parameters

2.1 x,y

x = np.random.normal(175, 5, N)
y = np.random.normal(60, 5, N)

x and y respectively represent the horizontal and vertical coordinates of a set of data

2.2 s,c

import matplotlib.pyplot as plt
import numpy as np

plt.figure('scatter', facecolor="lightgray")
plt.subplot(1, 2, 1)
plt.scatter(6, 8, s=44, c="r")
plt.subplot(1, 2, 2)
plt.scatter(3, 4, s=14, c="b")
plt.show()

insert image description here

s: represents the size of the coordinate point
c: represents the color of the coordinate point

2.3 cmap

It needs to be used in conjunction with the parameter c

Case 1:
c can be a sequence, for example: plt.scatter([1,2,3],[4,5,6],c=['r','b','r'])
insert image description here
case 2:

# cmap是一个颜色映射集,为参数序列c中的值分别分配一个颜色
import matplotlib.pyplot as plt
import numpy as np

plt.figure('scatter', facecolor="lightgray")
N = 300
x = np.random.normal(175, 5, N)
y = np.random.normal(60, 5, N)
b = (x - 175) ** 2 + (y - 60) ** 2
plt.scatter(x, y, s=14, c=b, cmap='hsv_r')

plt.show()

The result display:
insert image description here

2.4 norm vmin、vmax

Data brightness, value range: 0-1, if norm is used, vmin and vmax will be invalid

Guess you like

Origin blog.csdn.net/m0_51489557/article/details/129973305