On_selection event in faceted plot only works correctly in first facet
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
Hello,
I’m trying to catch on_selection events in a faceted figure.
I create a simple faceted figure, and attach an on_selection handler to all traces.
As an output, I simply print the customdata, and the selector.xrange.
When selecting an area in the first facet, the selector.xrange is an array of numbers, the customdata corresponds to the data for the left facet.
However, when I do the same in the second facet, the selector.xrange becomes an , and the customdata still appears to be coming from the left facet.
I expect the selector.xrange to also be an array of numbers, when selecting in the right facet.
Here are the sample code (to be executed in jupyter notebook) and a screenshot of the result.
py.init_notebook_mode()
df = pd.DataFrame({
"x": [1,2,3,4,1,2,3,4],
"y": [1,2,3,2,1,4,2,3],
"side": ["left","left","left","left","right","right","right","right"],
"customdata": [1,2,3,4,5,6,7,8]
})
fig = px.line(df, x="x", y="y", custom_data=["side","customdata"], facet_col="side")
# fig.update_layout(clickmode='event+select')
fig.update_layout(
dragmode="select",
clickmode="select"
)
fig.update_traces(marker_size=20)
f = go.FigureWidget(fig)
def click_handler(trace, points, selector):
print(trace.customdata)
print(selector.xrange)
f.data[0].on_selection(click_handler)
f
Kind Regards
Bart
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided faceted-plot example in a Jupyter notebook and inspect the FigureWidget selection callback attached through f.data[0].on_selection. Compare selector.xrange and trace.customdata when selecting the left and right facets. Done means selections in both facets report the appropriate numeric range and facet data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100