pylot的scatter函数制作散点图函数说明

来源:互联网 发布:广州数控车床编程图纸 编辑:程序博客网 时间:2024/06/06 20:47
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)Make a scatter plot of x vs y.Marker size is scaled by s and marker color is mapped to c.Parameters:x, y : array_like, shape (n, )Input datas : scalar or array_like, shape (n, ), optionalsize in points^2. Default is rcParams['lines.markersize'] ** 2.c : color, sequence, or sequence of color, optional, default: ‘b’c can be a single color format string, or a sequence of color specifications of length N, or a sequence of N numbers to be mapped to colors using the cmap and norm specified via kwargs (see below). 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. c can be a 2-D array in which the rows are RGB or RGBA, however, including the case of a single row to specify the same color for all points.marker : MarkerStyle, optional, default: ‘o’See markers for more information on the different styles of markers scatter supports. marker can be either an instance of the class or the text shorthand for a particular marker.cmap : Colormap, optional, default: NoneA Colormap instance or registered name. cmap is only used if c is an array of floats. If None, defaults to rc image.cmap.norm : Normalize, optional, default: NoneA 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 normalize().vmin, vmax : scalar, optional, default: Nonevmin and vmax are used in conjunction with norm to normalize luminance data. If either are None, the min and max of the color array is used. Note if you pass a norm instance, your settings for vmin and vmax will be ignored.alpha : scalar, optional, default: NoneThe alpha blending value, between 0 (transparent) and 1 (opaque)linewidths : scalar or array_like, optional, default: NoneIf None, defaults to (lines.linewidth,).verts : sequence of (x, y), optionalIf 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: NoneIf None, defaults to ‘face’If ‘face’, the edge color will always be the same as the face color.If it is ‘none’, the patch boundary will not be drawn.For non-filled markers, the edgecolors kwarg is ignored and forced to ‘face’ internally.Returns:paths : PathCollectionOther Parameters: **kwargs : Collection properties
import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)N = 100r0 = 0.6x = 0.9 * np.random.rand(N)y = 0.9 * np.random.rand(N)area = np.pi * (10 * np.random.rand(N))**2  # 0 to 10 point radiic = np.sqrt(area)r = np.sqrt(x * x + y * y)area1 = np.ma.masked_where(r < r0, area)area2 = np.ma.masked_where(r >= r0, area)plt.scatter(x, y, s=area1, marker='^', c=c)plt.scatter(x, y, s=area2, marker='o', c=c)# Show the boundary between the regions:theta = np.arange(0, np.pi / 2, 0.01)plt.plot(r0 * np.cos(theta), r0 * np.sin(theta))plt.show()


原创粉丝点击