首页 > 解决方案 > 同一轴上的多个散点图

问题描述

我有 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 的组合。

标签: pythonmatplotlibdata-visualizationscatter-plot

解决方案


如果颜色plot4可能与原来的颜色不同,您可以执行以下操作:

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([x1, x2, x3], [y1, y2, y3], color=('violet'), s = 10)

在此处输入图像描述

但是,如果您希望所有图的颜色与三个子图中的颜色相同,您可以按照 Brendan 的建议进行操作


推荐阅读