python - 同一轴上的多个散点图

标签 python matplotlib data-visualization scatter-plot

我有 3 个散点图,想知道如何将这 3 个散点图组合成 1 个大散点图。

我似乎无法仅使用 Matplotlib 找到此特定问题的解决方案。

x1 = np.random.randint(40, 100, 50)
y1 = np.random.randint(40, 100, 50)

x2 = np.random.randint(0, 60, 50)
y2 = np.random.randint(0, 60, 50)

x3 = np.random.randint(40, 100, 50)
y3 = np.random.randint(0, 60, 50)

fig, (plot1, plot2, plot3, plot4) = plt.subplots(1, 4)

plot1.scatter(x1,y1, color='green', s = 10)
plot1.set(xlim=(0, 100), ylim=(0, 100))

plot2.scatter(x2,y2, color='red', s = 10)
plot2.set(xlim=(0, 100), ylim=(0, 100))

plot3.scatter(x3,y3, color='blue', s = 10)
plot3.set(xlim=(0, 100), ylim=(0, 100))

plot4.scatter(plot1, plot2, plot3)

所以我希望plot4是plot1、plot2和plot3的组合。

最佳答案

简单地在 plot4 上绘制每个原始图:

plot4.scatter(x1,y1, color='green', s = 10)
plot4.scatter(x2,y2, color='red', s = 10)
plot4.scatter(x3,y3, color='blue', s = 10)

enter image description here

或者,您可以使用 np.concatenate() 组合每个 xy 数组,仅调用一次绘图命令,但这失去了独立为每个子组着色的能力。

plot4.scatter(np.concatenate((x1,x2,x3)), 
              np.concatenate((y1,y2,y3)), 
              color='black', s=10)

关于python - 同一轴上的多个散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57080406/

相关文章:

python - Python 中的错误消息 "MemoryError"

python - 如何检查变量是否是类?

python - 如何在Google Colab上安装和使用 basemap ?

python - 如何在numpy中将图像(28,28,1)转换为(28,28,3)

Python创建普通数组的多维数组

python - Django:model.objects.create() 更改了之前的 model.objects.filter() 的结果集

python - 粒子与盒子内壁的碰撞

google-analytics - 数据工作室 | "No Data"设置日期范围时

javascript - 如何使用图表数据更改 D3 Dimple 工具提示?

r - 绘制一个变量变化而其他变量不变的模型的函数