У меня есть код, изложенный в блокноте Jupyter следующим образом:
# Ask user for the Site they would like to view data for
Site = input("Enter the Site number that you would like to see data for: ")
# Choose the dataset based on the user input
if Site == '1':
df = site1_df
else:
df = site2_df
И в следующей ячейке у меня есть интерактивная ячейка построения графика, используя ipywidgets
следующим образом:
@interact
def line_plot(Variable=list(df.select_dtypes('number').columns),
time=widgets.ToggleButtons(options=['Raw', 'Minute', 'Hour', 'Day', 'Month'],
description='Time'),
color_button=widgets.ToggleButtons(options=['polar', 'solar', 'henanigans'],
description='Plot Theme'),
color_scale=widgets.ToggleButtons(options=['spectral', 'pastel1', 'polar', 'dark2'],
description='Colour Scale')):
# The following resamples the data based on the user selection
if time == 'Raw':
new_df = df.resample('30S').mean()
elif time == 'Minute':
new_df = df.resample('T').mean()
elif time == 'Hour':
new_df = df.resample('H').mean()
elif time == 'Day':
new_df = df.resample('D').mean()
else:
new_df = df.resample('M').mean()
# The newly resampled data is then plotted based on the users choice
new_df.iplot(kind='line', y=Variable, xTitle='Time', yTitle='Test',
mode='lines', theme=color_button, colorscale=color_scale)
Есть и другие элементы оптимизации, которые мне нужно сделать, но я бы хотел выбрать Site
в качестве выпадающего меню, как и другие на прилагаемом скриншоте. Но я не могу интегрировать его, поэтому опция, выбранная для Site
, изменяет отображаемые Variables
. Я видел некоторые другие посты по этому вопросу, но не могу интегрировать это для моей ситуации. Любая помощь приветствуется!
