<jupyter_start><jupyter_text>Exercises 2: Linking Plots In this exercise we will link plots generated with `hvplot` from the earthquake data using HoloViews linked selections. Loading the data as before<jupyter_code>import pandas as pd
import holoviews as hv # noqa

import hvplot.pandas # noqa: adds hvplot method to pandas objects
import hvplot.xarray # noqa: adds hvplot method to xarray objects
df = pd.read_parquet('../../data/earthquakes-projected.parq')
df.time = df.time.astype('datetime64[ns]')
df = df.set_index(df.time)
most_severe = df[df.mag >= 7]<jupyter_output><empty_output><jupyter_text>The distribution of earthquakes over space  Over latitudeSo far we have seen linked histograms but the same approach generalizes to many other plot types. This time we shall use `kind='scatter'` to generate scatter plots instead of histograms.First create a scatter called `lat_scatter` that plots the latitudes of the `most_severe` earthquakes over time. Customize it by making the scatter points red plus markers (`+`) and the plot responsive with height of `300` pixels. At the end of the cell, display this object.HintThe time of the earthquakes are in the `'time'` column while the latitudes are in the `'latitude'` column of `most_severe`. The scatter point color is controlled by the `color` keyword argument and `'red'` is a valid color specification. The height is controlled by a keyword of the same name and `marker='+'` will use that marker style.<jupyter_code>lat_scatter = ... # Use hvplot here to visualize a latitude scatter from most_severe
lat_scatter  # Display it<jupyter_output><empty_output><jupyter_text>Solution```pythonlat_scatter = most_severe.hvplot(     x='time', y='latitude', kind='scatter', color='red', marker='+', responsive=True, height=300)lat_scatter ```  Combined with a longitude scatter plotNow make a corresponding scatter plot over longitude called `lon_scatter` that plots the longitudes of the `most_severe` earthquakes over time. Customize it by making the scatter out of blue cross markers (`x`) with the same height of `300` pixels as before. It should be responsive and at the end of the cell, display this object in a layout with the previous `lat_scatter` plot. The longitude plot should be on the left and the latitude plot should be on the right. HintThis plot is identical to the previous one except the name of the handle and the fact that the `'longitude'` column is now used and the points are colored blue. To combine the plots together, use the previous handle of `lat_scatter` to create a layout with `lon_scatter` and the HoloViews `+` operator.<jupyter_code>lon_scatter = ... # Use hvplot here to visualize a longitude scatter from most_severe
# Display it to the left of lat_scatter<jupyter_output><empty_output><jupyter_text>Solution```pythonlon_scatter = most_severe.hvplot(         x='time', y='longitude', kind='scatter', color='blue', marker='x', responsive=True, height=300)lon_scatter + lat_scatter``` Now we have two scatter plots derived from the `most_severe` `DataFrame` but right now they are not linked. Linking the scatter plotsNow we can use `hv.link_selections` to link these two scatter plots together. Create the same layout as before with the longitude scatter on the left and the latitude scatter on the right, but this time link them together.HintYou will need to make a linked selection instance with `hv.link_selections.instance()` and pass the scatter layout to that instance in order to link the plots.<jupyter_code># Display a longitude scatter on the left that is linked to a latitude scatter on the right<jupyter_output><empty_output><jupyter_text>Solution    Combining the plots as well as the linked selection:```pythonls = hv.link_selections.instance()lat_scatter = most_severe.hvplot(     x='time', y='latitude', kind='scatter', color='red', marker='+', responsive=True, height=300)lon_scatter = most_severe.hvplot(         x='time', y='longitude', kind='scatter', color='blue', marker='x', responsive=True, height=300)ls(lon_scatter + lat_scatter)``` Use the box select tool to confirm that these plots are now linked. Note that you can reset the selection with the reset button in the Bokeh toolbar. Analysing the filtered selectionNow that we have linked plots, we can interactively select points in the visualization and then use that selection to filter the original `DataFrame`. After making a selection in the plot above, show a statistical summary of the points that have been selected.HintThe linked selection object has a `.filter` method that can filter your original `DataFrame` (`most_severe`). To compute statistics of a `DataFrame`, you can use the pandas `.describe()` method.<jupyter_code># Display a summary of a linked selection in the plot above using the pandas .describe()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07612528521053723, 'fraction_numerical': 0.0045633685957270275, 'mean_word_length': 5.5162162162162165, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '296854', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1269, 'n_words': 622, 'path': 'examples/tutorial/exercises/Linking_Plots.ipynb', 'repo_name': 'ablythed/holoviz', 'size': '4821'}