From 89bd009ff2f160b93b0e059445bfb5caae167b35 Mon Sep 17 00:00:00 2001 From: Anita Graser Date: Fri, 9 Dec 2022 12:34:00 +0100 Subject: [PATCH] Add linked selections example --- notebooks/environment.ipynb | 62 +++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/notebooks/environment.ipynb b/notebooks/environment.ipynb index 225ea67..7131db1 100644 --- a/notebooks/environment.ipynb +++ b/notebooks/environment.ipynb @@ -92,7 +92,63 @@ "outputs": [], "source": [ "col = 'airtemp °C'\n", - "stations.join(air_quality).dropna(subset=[col]).hvplot(geo=True, tiles='StamenToner', c=col, size=500, title=col.title())" + "stations = stations.join(air_quality).dropna(subset=[col])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "stations.hvplot(geo=True, tiles='StamenToner', c=col, size=500, title=col.title())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from holoviews.selection import link_selections" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "my_map = stations.hvplot(geo=True, tiles='CartoLight', c=col, cmap='Viridis', size=200, title=col.title(), width=400, height=250)\n", + "my_scatter = pd.DataFrame(stations).hvplot.scatter(x='airtemp °C', y='windspeed kmh', width=250, height=250)\n", + "my_hist = pd.DataFrame(stations).hvplot.hist('airtemp °C', width=250, height=250)\n", + "link_selections(my_map + my_hist + my_scatter , index_cols=['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import panel as pn" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def my_plot(my_col='airtemp °C'):\n", + " try: \n", + " my_map = stations.hvplot(geo=True, tiles='CartoLight', c=my_col, cmap='Viridis', size=200, title=my_col, width=400, height=250)\n", + " my_hist = pd.DataFrame(stations).hvplot.hist(my_col, title=my_col, width=250, height=250)\n", + " return link_selections(my_map + my_hist, index_cols=['id']) \n", + " except:\n", + " pass\n", + "kw = dict(my_col=air_quality.columns)\n", + "pn.interact(my_plot, **kw)" ] }, { @@ -105,7 +161,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -119,7 +175,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.8" + "version": "3.7.15" } }, "nbformat": 4,