Description
The Problem
Using fig.add_{hline, vline, hrect, vrect}
on a plotly.express object is not working as described in the docs. Following along with the simple example given:
iris = px.data.iris()
fig = px.scatter(iris, x='petal_length', y='petal_width')
fig.add_hline(y=0.9)
fig.add_vrect(x0=0.9, x1=2)
fig.show()
Displays the following in a notebook running in Visual Studio Code:
I originally discovered this behavior when placing a vline on a px.line figure in dash:
df = foo.get_history()
fig = px.line(df, template='ggplot2')
fig.add_vline(x='2020-10-30', line_width=3, line_dash='dash', line_color='red')
The line is drawn on the correct date, but only from 0 to 1.
Intended Behavior
The y extents of the vrect should encompass the entire plot area and the hline should extend across the entire plot area horizontally. Instead, they are fixed to 0 and 1.
Probable Cause
It seems that the add_{hline, vline, hrect, vrect}
methods in basedatatypes.py
for BaseFigure
set these values in the call to self._process_multiple_axis_spanning_shapes(,...)
. For example, the add_vline()
method:
Proposed Solution
It seems like we should just be able to find the x/y axis range and set the x0/x1/y0/y1 based on that, but I'm not sure how to get to those values. I'm a bit short on time this morning, but I may have a crack at this in the afternoon.