Matplotlib.pyplot:在子图上绘制对角线

Matplotlib.pyplot:在子图上绘制对角线,matplotlib,seaborn,Matplotlib,Seaborn,我想在两个图上各显示一条对角线,实际上是一条45度的线。我找到了如何在轴上绘制水平线和垂直线,但我找不到如何绘制任意线。鹰眼设计人@ImportanceOfBeingEarnest发现我创建线的参数不正确: 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_un

我想在两个图上各显示一条对角线,实际上是一条45度的线。我找到了如何在轴上绘制水平线和垂直线,但我找不到如何绘制任意线。

鹰眼设计人@ImportanceOfBeingEarnest发现我创建线的参数不正确:

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()
我把它们写成第一对是起点的坐标,第二对是终点的坐标。实际上,第一个参数是x坐标的列表,第二个参数是y坐标的列表,所以我的直线实际上定义了一个点。解决我的问题的正确方法是:

ax1.plot([-1, -1], [1, 1], 'red', linewidth=10)

这可能更容易,因为它是自动的

我想你忘了告诉你面临的实际问题。代码不是。但是只要看看它,坐标似乎是错误的,而不是绘图[-1,-1],[1,1],你可能真的想使用绘图[-1,1],-1,1]?可能的重复不是重复。谢谢你添加了一个答案。作为旁注,如果您愿意,您可以通过单击勾选/复选标记自行接受此答案。
ax1.plot([-1,1],[-1,1], 'red', linewidth=10)
fig, axes = plt.subplots(1,2)
df_sj_Y_pred.plot(x=['predictions'], y=['total_cases'], kind="scatter", color='black', label='SJ', ax=axes[0])
df_iq_Y_pred.plot(x=['predictions'], y=['total_cases'], kind="scatter", color='red', label='iq', ax=axes[1])
x = np.linspace(*axes[0].get_xlim())
axes[0].plot(x, x, c='orange')
x = np.linspace(*axes[1].get_xlim())
axes[1].plot(x, x)
axes[0].set(title="sj Predicted vs. Actual")
axes[1].set(title="iq Predicted vs. Actual") #, aspect='equal')
fig.suptitle("Comparing SJ & IQ")
plt.legend()
plt.savefig("/tmp/QQ.png")
plt.show()