# Linked brushing with bar chart

**URL:** <https://discourse.holoviz.org/t/linked-brushing-with-bar-chart/6049>\
**Category:** HoloViews\
**Tags:** link-selection\
**Created:** [September 18, 2023, 7:43pm UTC](https://discourse.holoviz.org/t/linked-brushing-with-bar-chart/6049 "2023-09-18T19:43:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anitagraser](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/anitagraser/32/158_2.png) [@anitagraser](https://discourse.holoviz.org/u/anitagraser)\
**Post date:** [September 18, 2023, 7:43pm UTC](https://discourse.holoviz.org/t/linked-brushing-with-bar-chart/6049/1 "2023-09-18T19:43:49Z")

</div>

What is the easiest way to link a scatter plot and a bar chart?

Linked brushing does not support bar charts ([Linked Brushing — HoloViews v1.17.1](https://holoviews.org/user_guide/Linked_Brushing.html)) but [https://awesome-panel.org/kickstarter\_dashboard](https://awesome-panel.org/kickstarter_dashboard) shows that it is still possible to link a scatter plot and a bar chart (i.e. when we zoom into the scatter plot, the bar plot is filtered) but the code is far from a minimum working example and – since it is dated 2019 – I’m wondering if there are newer, more straightforward approaches?

Here’s the minimum example of scatterplot + bar, I’d like to start with: [https://github.com/movingpandas/movingpandas-examples/blob/main/3-tech-demos/linked-brushing.ipynb](https://github.com/movingpandas/movingpandas-examples/blob/main/3-tech-demos/linked-brushing.ipynb) (cell no. 7):

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/d/dfabe3b1cc218ce449ea260a26c29826655d8214.png)

---

<div class="post-metadata">

**Author:** ![anitagraser](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/anitagraser/32/158_2.png) [@anitagraser](https://discourse.holoviz.org/u/anitagraser)\
**Post date:** [September 18, 2023, 8:14pm UTC](https://discourse.holoviz.org/t/linked-brushing-with-bar-chart/6049/2 "2023-09-18T20:14:06Z")

</div>

Ok, found it thanks to [Linked tap selections in stacked bar plots - #2 by Marc](https://discourse.holoviz.org/t/linked-tap-selections-in-stacked-bar-plots/956/2) and [RangeXY — HoloViews v1.17.1](https://holoviews.org/reference/streams/bokeh/RangeXY.html)

```auto
def selected_bar_plot(x_range, y_range):
    if x_range:
        tmp = df[(df.x>x_range[0])&(df.x<x_range[1])]
    else:
        tmp = df
    return tmp.groupby("ShipType").count().hvplot.bar(x="ShipType", y='MMSI', width=400, rot=90)

map_plot = df.hvplot.scatter(x='x', y='y', c="ShipType", width=700, height=300)
rangexy = hv.streams.RangeXY(source=map_plot)
    
map_plot << hv.DynamicMap(selected_bar_plot, streams=[rangexy])

```

![linked-bar](https://discourse.holoviz.org/uploads/default/original/2X/4/4deb097ed420e69bc8522ae9e69c7d0e87a7fb40.gif)
