python - 同一轴上的多个散点图
问题描述
我有 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
可能与原来的颜色不同,您可以执行以下操作:
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 的建议进行操作
推荐阅读
- php - 使用 Goutte 爬取表格
- javascript - 如何获取元素的所有基本属性
- r - r 中的组(住房数据)
- javascript - 如何将 JSX 反应对象返回到网页?
- azure - 一个目录可以创建多少个Azure B2C
- java - 检查两个二维布尔数组是否在给定间隔相等:Java
- spring-boot - 如果对象列表中的字段值重复,是否有 java validate 的注释?
- php - 在 PHP 中使用数组以随机顺序回显数字
- amazon-web-services - SNS 向已删除的订阅发送消息
- c# - 在 C# 中从 Google Drive 或类似的 Android 读取/写入远程文本