【发布时间】:2020-07-26 21:41:17
【问题描述】:
您好,我正在尝试创建:
- 水平堆叠的地块
- 在两个图上都有次轴
- 在轴上有不同的比例 - 不幸的是,我的两个 Y 轴目前每个子图都有相同的比例...:(
当前代码:
# Create axes
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle("XYZ")
fig.set_figheight(5)
fig.set_figwidth(15)
# First graph
ax1.scatter(
df_PTA_clip_pstar["start_time"],
df_PTA_clip_pstar["pstar"],
s=5,
c="black",
label="P*",
)
plt.ylabel("P*")
ax1.scatter(df_PTA_clipkh["start_time"], df_PTA_clipkh["kh"], s=2, c="cyan", label="Kh")
ax1.secondary_yaxis("right")
plt.ylabel("Kh")
# Second graph - will add the correct data to this once first graph fixed
ax2.scatter(x, y, s=5, c="Red", label="P*")
ax2.scatter(x, z, s=5, c="Green", label="Kh")
ax2.secondary_yaxis("right")
plt.tight_layout()
plt.legend()
plt.show()
目前进展:
【问题讨论】:
-
可能会看到 Plots with different scales 在轴对象上使用
.twinx()方法。 -
将其与两个水平堆叠的图一起使用意味着无法绘制第二个图,因为定义的两个斧头已被“使用”
标签: python matplotlib subplot