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

I want to display a diagonal line over each of the two plots, in fact a 45 degree line. I found how to draw horizontal and vertical lines over axes but I can't find how to draw an arbitrary line.

halfer
  • 19,824
  • 17
  • 99
  • 186
pitosalas
  • 10,286
  • 12
  • 72
  • 120
  • 1
    I think you forgot to tell the actual problem you face. The code is no [mcve]. But just looking at it, the coordinates seem to be wrong, instead of `plot([-1,-1],[1,1])` you might actually mean to use `plot([-1,1],[-1,1])`? – ImportanceOfBeingErnest Apr 29 '18 at 21:57
  • 1
    Possible duplicate of [Adding y=x to a matplotlib scatter plot if I haven't kept track of all the data points that went in](https://stackoverflow.com/questions/25497402/adding-y-x-to-a-matplotlib-scatter-plot-if-i-havent-kept-track-of-all-the-data) – Paul H Apr 30 '18 at 00:59
  • It's not a duplicate. – pitosalas Apr 30 '18 at 20:37

2 Answers2

2

Eagle eyed contribotor @ImportanceOfBeingEarnest spotted that my parameters for creating the line were incorrect:

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

I wrote them as if the first pair were coordinates of the start point, and the second pair were coordinates of the end point. In reality the first argument is a list of x coordinates, and the second argument a list of y coordinates, so my line was actually defining a point. The correct way and which solved my problem would be:

ax1.plot([-1,1],[-1,1], 'red', linewidth=10)
pitosalas
  • 10,286
  • 12
  • 72
  • 120
  • 1
    Thanks for adding an answer. As a side note, you can self-accept this answer by clicking the tick/check mark, if you wish. – halfer May 05 '18 at 18:46
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()

This might work easier as it's auto

user6273920
  • 713
  • 1
  • 7
  • 16