In use matplotlib Scatter () plotted scattergram

1, a two-dimensional scatter plot

Two-dimensional scatter plot function prototype:

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)
  • x, yCorresponding to the plane position of the point,
  • sControl point size,
  • cCorresponding color indication value, i.e. if the gradient, we set the c=xcan so that the color point according to the point of xchange value,
  • cmapThe type of adjustment or color gradient list
  • markerShape control points
  • alphaTransparency control point, I like to set up large volumes of data in a small time alphavalue, and then adjust the svalue so that an overlap effect makes data aggregation features will show up nicely: look at the results

The first setting opaque

fig = plt.figure()

x = np.random.randn(10000)
y = np.random.randn(10000)
plt.scatter(x, y, c='b')
plt.scatter(x+4, y, c='r')

 

 The second set transparent

fig = plt.figure()

x = np.random.randn(10000)
y = np.random.randn(10000)
plt.scatter(x, y, c='b', alpha=0.05)
plt.scatter(x+4, y, c='r', alpha=0.05)

 

 Then adjust the size of the spot

fig = plt.figure()

x = np.random.randn(10000)
y = np.random.randn(10000)
plt.scatter(x, y, c='b', alpha=0.05, s=10)
plt.scatter(x+4, y, c='r', alpha=0.05, s=10)

 

 

2, three-dimensional scatter plot

Three-dimensional scatter plot function prototype:

p3d.Axes3D.scatter( xs, ys, zs=0, zdir=’z’, s=20, c=None, depthshade=True, 
                   *args, **kwargs )

p3d.Axes3D.scatter3D( xs, ys, zs=0, zdir=’z’, s=20, c=None, depthshade=True,
                   *args, **kwargs)

There are two versions of the three-dimensional scatter plot in p3d.Axes3D in, but the effect is the same:

  • xs, ysRepresentative point x, yaxis coordinates
  • zsRepresentative zaxis coordinate, but the two forms, the first is to take a scalar function prototype in default is a scalar 0, that is, by default all points are drawn on a z=0horizontal plane; the second is to take and xs, yssimilar shapeto array, thereby specifying the actual z-axis coordinate of each point, as follows:

zs The default is 0;

fig = plt.figure()
ax = Axes3D(fig)

x = np.random.randn(10000)
y = np.random.randn(10000)
ax.scatter(x, y, c='b', s=10, alpha=0.05)
ax.scatter(x+4, y, c='r', s=10, alpha=0.05)

 

 Take a scalar zs

fig = plt.figure()
ax = Axes3D(fig)

x = np.random.randn(10000)
y = np.random.randn(10000)
ax.scatter(x, y, c='b', s=10, alpha=0.05)
ax.scatter(x+4, y, 2, c='r', s=10, alpha=0.05)

 

 

 zs take an array

fig = plt.figure()
ax = Axes3D(fig)

z = 6*np.random.randn(5000)
x = np.sin(z)
y = np.cos(z)
ax.scatter(x, y, z, c='r', s=10, alpha=0.05)

 Reference: https: //www.jianshu.com/p/9390b49ad993

Guess you like

Origin www.cnblogs.com/mliu222/p/11920380.html