同一轴上的多个散点图

时间:2019-07-17 16:22:46

标签: 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的组合。

2 个答案:

答案 0 :(得分:0)

只需在#if DEBUG ../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe #else ../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Release/ConnectionBuilder.exe #endif 上绘制每个原始图:

plot4

enter image description here

或者,您可以使用plot4.scatter(x1,y1, color='green', s = 10) plot4.scatter(x2,y2, color='red', s = 10) plot4.scatter(x3,y3, color='blue', s = 10) 组合每个xy数组以仅调用一次plot命令,但这会失去分别为每个子组着色的能力。

np.concatenate()

答案 1 :(得分:0)

如果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)

enter image description here

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

相关问题