matplotlib.pyplot.scatter()方法详述

这个方法比较常用
原型:
matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)

参数列表
Parameters:
x, y  :  array_like, shape (n, )

The data positions.

s  :  scalar or array_like, shape (n, ), optional

The marker size in points**2. Default is rcParams['lines.markersize'] ** 2.

c  :  color, sequence, or sequence of color, optional, default: ‘b’

The marker color. Possible values:

  • A single color format string.
  • A sequence of color specifications of length n.
  • A sequence of n numbers to be mapped to colors using cmap and norm.
  • A 2-D array in which the rows are RGB or RGBA.

Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. If you want to specify the same RGB or RGBA value for all points, use a 2-D array with a single row.

marker  :  MarkerStyle, optional, default: ‘o’

The marker style. marker can be either an instance of the class or the text shorthand for a particular marker. See markers for more information marker styles.

cmap  :  Colormap, optional, default: None

Colormap instance or registered colormap name. cmap is only used if c is an array of floats. If None, defaults to rc image.cmap.

norm  :  Normalize, optional, default: None

Normalize instance is used to scale luminance data to 0, 1. norm is only used if c is an array of floats. If None, use the default colors.Normalize.

vmin, vmax  :  scalar, optional, default: None

vmin and vmax are used in conjunction with norm to normalize luminance data. If None, the respective min and max of the color array is used. vmin and vmax are ignored if you pass a norm instance.

alpha  :  scalar, optional, default: None

The alpha blending value, between 0 (transparent) and 1 (opaque).

linewidths  :  scalar or array_like, optional, default: None

The linewidth of the marker edges. Note: The default edgecolors is ‘face’. You may want to change this as well. If None, defaults to rcParams lines.linewidth.

verts  :  sequence of (x, y), optional

If marker is None, these vertices will be used to construct the marker. The center of the marker is located at (0, 0) in normalized units. The overall marker is rescaled by s.

edgecolors  :  color or sequence of color, optional, default: ‘face’

The edge color of the marker. Possible values:

  • ‘face’: The edge color will always be the same as the face color.
  • ‘none’: No patch boundary will be drawn.
  • A matplotib color.

For non-filled markers, the edgecolors kwarg is ignored and forced to ‘face’ internally.

Returns:
paths  :  PathCollection
Other Parameters:
**kwargs  :  Collection properties

想翻译一下的,但是感觉用的词不恰当,还是保留英文的吧!

放个例子:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(10)

N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2 

plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()


猜你喜欢

转载自blog.csdn.net/weixin_40941966/article/details/80896272