As of plotly version 4.12, you can add Horizontal and Vertical Lines and Rectangles. I have installed plotly 4.12. I am using the following snippet:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="petal_length", y="petal_width")
fig.add_vline(x=2.5, line_width=3, line_dash="dash", line_color="green")
fig.add_hrect(y0=0.9, y1=2.6, line_width=0, fillcolor="red", opacity=0.2)
fig.show()
... which produces this figure:
Why does the vline does not extend indefinetely on the y axis?
Same problem is described here github.com/plotly/plotly.py/issues/2979 but no solution is provided. I can find descriptions of a workaround here: Plotly: how to make an unbounded vertical line in a subplot? but the workaround is quite verbose and not so neat.
I would really like to use the add_vline functionality and I am a bit puzzled as documentation clearly says "Add a vertical line to a plot or subplot that extends infinitely in the y-dimension." and all examples here extends beyond 1 too: Therefore it looks to me like the intended behavior should be to have the line extends beyond 1.