0

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:

enter image description here

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.

Mth Clv
  • 625
  • 1
  • 7
  • 20

1 Answers1

0

The add_vline function uses recently-added features in the underlying rendering engine, Plotly.js, meaning you need a recent version of Plotly.js wherever you are using Plotly.py. In practice this means installing the latest jupyterlab-plotly extension in JupyterLab, the latest dash/dash_core_components in Dash, or waiting until VSCode and/or Streamlit update their onboard copies of Plotly.js, if you’re seeing this problem in those environments.

More information can be found here: Troubleshooting | Python | Plotly

Mth Clv
  • 625
  • 1
  • 7
  • 20