BUG: Cannot get xref / yref to work with "<x/y> domain" string

I have been trying to work with adding annotations to subplots in plotly.py (I have tried v4.9.0 and v4.14.3) based off of the reference documentation (Text and Annotations | Python | Plotly) as well as this nifty SOE answer (https://stackoverflow.com/a/67363429).

However, the issue I keep running into is that Plotly.py does not seem to have support for this type of xref/yref option even though the documentation and examples show it.

Code being run:

import plotly.express as px
import plotly.graph_objects as go

df = px.data.wind()
fig = px.scatter(df, y="frequency")

# Set a custom domain to see how the ' domain' string changes the behaviour
fig.update_layout(xaxis=dict(domain=[0, 0.5]), yaxis=dict(domain=[0.25, 0.75]))

fig.add_annotation(
    xref="x domain",
    yref="y domain",
    # The arrow head will be 25% along the x axis, starting from the left
    x=0.25,
    # The arrow head will be 40% along the y axis, starting from the bottom
    y=0.4,
    text="An annotation referencing the axes",
    arrowhead=2,
)

# fig.show()

Error traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-51-71bdb688735c> in <module>
      8 fig.update_layout(xaxis=dict(domain=[0, 0.5]), yaxis=dict(domain=[0.25, 0.75]))
      9 
---> 10 fig.add_annotation(
     11     xref="x domain",
     12     yref="y domain",

/opt/conda/lib/python3.8/site-packages/plotly/graph_objs/_figure.py in add_annotation(self, arg, align, arrowcolor, arrowhead, arrowside, arrowsize, arrowwidth, ax, axref, ay, ayref, bgcolor, bordercolor, borderpad, borderwidth, captureevents, clicktoshow, font, height, hoverlabel, hovertext, name, opacity, showarrow, standoff, startarrowhead, startarrowsize, startstandoff, templateitemname, text, textangle, valign, visible, width, x, xanchor, xclick, xref, xshift, y, yanchor, yclick, yref, yshift, row, col, secondary_y, **kwargs)
  18298         from plotly.graph_objs import layout as _layout
  18299 
> 18300         new_obj = _layout.Annotation(
  18301             arg,
  18302             align=align,

/opt/conda/lib/python3.8/site-packages/plotly/graph_objs/layout/_annotation.py in __init__(self, arg, align, arrowcolor, arrowhead, arrowside, arrowsize, arrowwidth, ax, axref, ay, ayref, bgcolor, bordercolor, borderpad, borderwidth, captureevents, clicktoshow, font, height, hoverlabel, hovertext, name, opacity, showarrow, standoff, startarrowhead, startarrowsize, startstandoff, templateitemname, text, textangle, valign, visible, width, x, xanchor, xclick, xref, xshift, y, yanchor, yclick, yref, yshift, **kwargs)
   1913         _v = xref if xref is not None else _v
   1914         if _v is not None:
-> 1915             self["xref"] = _v
   1916         _v = arg.pop("xshift", None)
   1917         _v = xshift if xshift is not None else _v

/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py in __setitem__(self, prop, value)
   3988                 # ### Handle simple property ###
   3989                 else:
-> 3990                     self._set_prop(prop, value)
   3991             else:
   3992                 # Make sure properties dict is initialized

/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py in _set_prop(self, prop, val)
   4306                 return
   4307             else:
-> 4308                 raise err
   4309 
   4310         # val is None

/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py in _set_prop(self, prop, val)
   4301 
   4302         try:
-> 4303             val = validator.validate_coerce(val)
   4304         except ValueError as err:
   4305             if self._skip_invalid:

/opt/conda/lib/python3.8/site-packages/_plotly_utils/basevalidators.py in validate_coerce(self, v)
    594             v = self.perform_replacemenet(v)
    595             if not self.in_values(v):
--> 596                 self.raise_invalid_val(v)
    597         return v
    598 

/opt/conda/lib/python3.8/site-packages/_plotly_utils/basevalidators.py in raise_invalid_val(self, v, inds)
    273                 name += "[" + str(i) + "]"
    274 
--> 275         raise ValueError(
    276             """
    277     Invalid value of type {typ} received for the '{name}' property of {pname}

ValueError: 
    Invalid value of type 'builtins.str' received for the 'xref' property of layout.annotation
        Received value: 'x domain'

    The 'xref' property is an enumeration that may be specified as:
      - One of the following enumeration values:
            ['paper']
      - A string that matches one of the following regular expressions:
            ['^x([2-9]|[1-9][0-9]+)?$']
​

Are you using the latest version of the plotly package? It’s 4.14.3.

@nicolaskruchten yes, I have tried v4.9.0 and v4.14.3

Albeit, one consideration to keep in mind is I am utilizing Python 3.8.5 since it is what my institution supports on JupyterHub where I need to develop this application.

Have you installed the latest version of the jupyterlab-plotly extension (i.e. 4.14.3) per Troubleshooting | Python | Plotly ?

@nicolaskruchten Force updating everything to the newest plotly releases (4.14.3) and running jupyter lab build made it all work, thank you!! :slight_smile: