plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Choropleth: can't add/remove from current selection after zoom

Open araichev opened this issue 9 months ago • 2 comments

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!

araichev avatar Mar 19 '25 02:03 araichev

@araichev I think this is a bug - thank you for reporting it. Realistically, though, it will be quite a while before we can get to it - if you or someone in the community would like to submit a PR, we can try to prioritize review. thanks - @gvwilson

gvwilson avatar Mar 19 '25 18:03 gvwilson

Thanks @gvwilson . Submitting a fix is beyond my skill level, so we'll see if someone else volunteers.

araichev avatar Mar 19 '25 21:03 araichev