一只萌萌小番薯
对于不同的标记样式,您当前需要创建不同的绘图实例(请参阅此 github 问题)。可以通过将数组作为color参数传递来使用不同的颜色。例如:import matplotlib.pyplot as pltimport numpy as npdata = np.array([ [1, 0.15], [1, 1957], [1, 1], [2, 346], [2, 0.90], [2, 100], [3, 1920], [3, 100], [3, 40],])x, y = np.transpose(data)symbols = ['o', 's', 'D']colors = ['blue', 'orange', 'green']for value, marker in zip(np.unique(x), symbols): mask = (x == value) plt.scatter(x[mask], y[mask], marker=marker, color=colors)plt.show()
米脂
我要做的是将数据分成三个不同的列,这样你就有了几个系列。然后我会使用带有不同标记的 plt.scatter 来获得所需的效果。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 = (20 * np.random.rand(N))**2 # 0 to 10 point radiic = np.sqrt(area)r = np.sqrt(x ** 2 + y ** 2)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()来源:https ://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/scatter_masked.html#sphx-glr-gallery-lines-bars-and-markers-scatter-masked-py