matplotlib - Matplotlib.pyplot:在 subplo 上绘制对角线
问题描述
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, sharey=True)
ax1.plot([-1, -1], [1, 1], linewidth=10, c="red")
sns.regplot(x=early_mean_zscore_untreated, y=late_mean_zscore_untreated, data=combo_untreated, ax=ax1, fit_reg=False)
sns.regplot(x=early_mean_zscore_treated, y=late_mean_zscore_treated, data=combo_treated, ax=ax2, fit_reg=False)
ax1.set(xlabel="Z-score for early PAs", ylabel="Z-score for late PAs")
ax2.set(xlabel="Z-score for early PAs", ylabel="Z-score for late PAs")
ax1.set(title="Resubmitted <= %d times" % resub_cutoff, aspect='equal')
ax2.set(title="Resubmitted > %d times" % resub_cutoff, aspect='equal')
fig.suptitle("Comparing improvement over the semester\nZ-scores")
ax1.plot([-1, -1], [1, 1], 'red', linewidth=10, )
plt.savefig("graphm.png")
plt.show()
我想在两个图的每一个上显示一条对角线,实际上是一条 45 度线。我找到了如何在轴上绘制水平线和垂直线,但我找不到如何绘制任意线。
解决方案
老鹰眼的贡献者@ImportanceOfBeingEarnest 发现我创建这条线的参数不正确:
ax1.plot([-1, -1], [1, 1], 'red', linewidth=10)
我把它们写成第一对是起点的坐标,第二对是终点的坐标。实际上,第一个参数是 x 坐标列表,第二个参数是 y 坐标列表,所以我的线实际上是定义一个点。解决我的问题的正确方法是:
ax1.plot([-1,1],[-1,1], 'red', linewidth=10)
推荐阅读
- r - R Mosek 使用二次规划
- machine-learning - 我的 CNN 模型的权重没有完全打印出来
- ios - Xamarin 窗体 iOS WebRTC
- android - 如何更改应用背景的标题颜色?
- python - 在docker中第二次运行时如何修复硒?
- mule - 如何将多个输入参数添加到 Mule 中的数据库连接器
- javascript - 如何修复反应 Heroku 中的 130 反应错误?
- java - 从 DatePicker 和 TimePicker 获取时间戳
- memory - Newtonsoft 的 HttpWebRequest 内存泄漏问题
- vim - Vim 目录内容?