Plotting a horizontal line on multiple subplots in python using pyplot
I found a way to do it for anyone who stumbles on this anyways.
We need to replace the following line from the OP:
plt.axhline(y=0.002, xmin=0, xmax=1, hold=None)
We replace it with:
ax1.axhline(y=0.002,xmin=0,xmax=3,c="blue",linewidth=0.5,zorder=0)ax2.axhline(y=0.002,xmin=0,xmax=3,c="blue",linewidth=0.5,zorder=0)ax3.axhline(y=0.002,xmin=0,xmax=3,c="blue",linewidth=0.5,zorder=0)
This produces:
Since you have defined ax1
, ax2
and ax3
, it is easy to draw horizontal lines on them. You need to do it separately for them. But your code could be simplified:
for ax in [ax1, ax2, ax3]: ax.axhline(y=0.002, c="blue",linewidth=0.5,zorder=0)
According to axhline documentation, xmin
and xmax
should be in the range (0,1). There is no chance that xmax=3.0
. Since your intent is to draw horizontal line across the axes (which is the default behavior of axhline
method ), you can just omit the xmin
and xmax
parameter.