Matplotlib.pyplot:在subplo上画一条对角线

时间:2018-04-29 20:59:39

标签: matplotlib seaborn

VALUES ('L500','MANDY','LOPEZ','01-OCT-09', 47000, 1500, 'NULL')

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

2 个答案:

答案 0 :(得分:0)

Eagle eyed contribotor @ImportanceOfBeingEarnest发现我创建该行的参数不正确:

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

我把它们写成好像第一对是起点的坐标,第二对是终点的坐标。实际上,第一个参数是x坐标列表,第二个参数是y坐标列表,所以我的线实际上定义了一个点。正确的方法解决了我的问题:

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

答案 1 :(得分:0)

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()

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

相关问题