Choropleth: can't add/remove from current selection after zoom
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.3k
- Forks
- 2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Description
I don't know if this is a bug or a missing feature, but i'd like to select polygons on a choropleth, zoom, then add/ remove from the current selection via shift+click.
This is especially useful when i want to remove a few central polygons from a big selection small polygons and need to select then zoom in to better see which few to remove.
This is already possible in (non-geographic) scatter plots: click to select, zoom, then shift-click to remove from selection, e.g.
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df.iloc[:20], x="sepal_width", y="sepal_length")
fig.update_layout(clickmode="event+select")
fig.show()
And it's already possible in choropleths without zooming between selecting and shift-clicking.
Here's a code snippet to reproduce the bug (or missing feature).
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')
fig = go.Figure(data=go.Choropleth(
locations=df['code'], # Spatial coordinates
z = df['total exports'].astype(float), # Data to be color-coded
locationmode = 'USA-states', # set of locations match entries in `locations`
colorscale = 'Reds',
colorbar_title = "Millions USD",
))
fig.update_layout(
title_text = '2011 US Agriculture Exports by State',
geo_scope='usa', # limite map scope to USA
clickmode="event+select",
)
fig.show()
Now box-select some polygons, then remove a polygon from the selection by shift-clicking it.
Works nicely.
Box-select some polygons again, zoom in, then try to remove a polygon from the selection by shift-clicking it.
No can do!
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
Start with the supplied Plotly Express scatter and plotly.graph_objects Choropleth reproductions, then trace the choropleth selection and geographic zoom interaction entry points in the repository. Confirm the existing no-zoom shift-click behavior and make the zoomed case preserve and update the current selection; done means the provided reproduction can remove a polygon after zooming, with coverage for that sequence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100