# Plotly selection not fully working when using facets

**URL:** <https://community.plotly.com/t/plotly-selection-not-fully-working-when-using-facets/75764>\
**Category:** 📊 Plotly Python\
**Created:** [June 1, 2023, 8:21pm UTC](https://community.plotly.com/t/plotly-selection-not-fully-working-when-using-facets/75764 "2023-06-01T20:21:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bart.verweire](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bart.verweire](https://community.plotly.com/u/bart.verweire)\
**Post date:** [June 1, 2023, 8:21pm UTC](https://community.plotly.com/t/plotly-selection-not-fully-working-when-using-facets/75764/1 "2023-06-01T20:21:37Z")

</div>

Hello,

I’m trying to use the plotly on\_selection handler, in a figure with facets.  
The handler does seem to work in the first facet, but not in the other facets.

An example below (based on [Selection events in Python/v3](https://plotly.com/python/v3/selection-events/))  
Using the cars data set, I create a scatter plot using “Number of Forward Gears” as facet column.

```auto
import plotly.graph_objs as go
import plotly.offline as py
import plotly.express as px

import pandas as pd
import numpy as np
from ipywidgets import interactive, HBox, VBox

py.init_notebook_mode()
df = pd.read_csv('https://raw.githubusercontent.com/jonmmease/plotly_ipywidget_notebooks/master/notebooks/data/cars/cars.csv')

df_range = df['City mpg'].max() - df['City mpg'].min()
df["x"] = df["City mpg"].apply(lambda x : x + np.random.rand()/10 * df_range)
df["y"] = df["City mpg"].apply(lambda x : x + np.random.rand()/10 * df_range)
df

fig = px.scatter(df, x="x", y="y", facet_col="Number of Forward Gears")
fig.update_layout(
            showlegend=False,
            dragmode="select",
            clickmode="select"
        )
fig = go.FigureWidget(fig)

def selection_fn(trace,points,selector):
    print(selector)
    
for scatter in fig.data:
    scatter.marker.opacity = 0.1
    scatter.on_selection(selection_fn)
    
fig

```

When you select in the first facet, the console log shows the selected xrange and yrange

```auto
BoxSelector(xrange=[14.674226120973662, 25.12143134859872],
            yrange=[14.112620683088675, 21.95971264686313])

```

However, from the second facet on, the BoxSelector displays some unuseful data :

```auto
BoxSelector(xrange=<object object at 0x000001BCD8F1D930>,
            yrange=<object object at 0x000001BCD8F1D930>)

```

Does someone have an idea what could be the cause, and if there’s a workaround ?  
Working with subplots shows the same behavior, by the way.

Thank you

Bart
