plotly.py
plotly.py copied to clipboard
Use different "xref" for "x" and "xclick" in annotations
Hello,
My basic goal is to have annotations that pop up in the top right corner of the figure/paper, when I click on a data point. I am trying to avoid doing it in dash, in the hopes that I can export to html and keep all functionality.
f = go.Figure()
f.add_trace(
go.Scatter(
x=[0, 1],
y=[0, 1],
text=["A", "B"],
marker={"size": 50},
mode="lines+markers+text",
)
)
annotation_opts = dict(
x=0.99,
xref="paper",
xanchor="right",
y=0.99,
yref="paper",
yanchor="top",
showarrow=False,
clicktoshow="onout",
visible=False,
)
f.add_annotation(text="A:<br>attribute: value", xclick=0, yclick=0, **annotation_opts)
f.add_annotation(text="B:<br>attribute: value", xclick=1, yclick=1, **annotation_opts)
The problem I am having is, that if I have xref and yref set to "paper", the clicks do not open the annotation. Without the refs the clicks work, but the location of the annotation is not fixed when I zoom or pan.
I assume this is because when I set the refs to "paper", xclick also looks for a click in reference to "paper" instead of the axis? If that is the case, could we get a xclickref and yclickref argument to set them separately?
Or am I approaching this the wrong way?