I have the following code, which plots a bunch of timeseries for different stations, and also makes a widget with which you can select a line to be highlighted.
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv
hv.extension('bokeh')
num_years = 10
num_stations = 5
data = {
'Year': np.tile(np.arange(2010, 2010 + num_years), num_stations),
'Station ID': np.repeat([f'Station_{i}' for i in range(1, num_stations + 1)], num_years),
'Precip': np.random.randint(1, 30, size=num_years * num_stations)
}
df = pd.DataFrame(data)
all_lines_plot = df.hvplot(
y='Precip',
x='Year',
by='Station ID',
color = 'grey',
alpha = .2,
legend=False
)
sel_lines_plot = df.hvplot(
y='Precip',
x='Year',
groupby='Station ID',
)
all_lines_plot*sel_lines_plot
This almost gets me what I want. However, I want the ability to select multiple different Station IDs with the widget. When multiple lines are selected, they should be plotted in different colors, and a legend should appear which ties the colors to the selected stations.
In the actual use case, there are thousands of Station IDs, so ideally, the widget should allow one to easily find Station IDs they want to be highlighted. Something where you can start typing in a Station ID, and it comes up with possible options based on what you typed so far, would be perfect.