Hello there!
I’m looking to ‘link’ my Dropdowns (buttons) to my hlines. For now these lines don’t update with the other traces (scatter and bar).
To explain :
- I have one button to select the column to plot
- The second button is for selecting the ‘sportif’ I want (like an ID)
Here is my code:
fig = go.Figure()
fig.add_scatter(
x = df_plot[df_plot['sportif'] == 'Joueur-10']['dateSeance'],
y = df_plot[df_plot['sportif'] == 'Joueur-10']['intensitemax'],
mode='lines+markers', fill='tozeroy', marker_color='#576DF3',
marker=dict(opacity=0.8,
size=3
),
line=dict(width=1
),
name='Seances'
)
fig.add_bar(
x = df_plot[(df_plot['sportif'] == 'Joueur-10') & (df_plot['nomSeance'] == 'Match')]['dateSeance'],
y = df_plot[(df_plot['sportif'] == 'Joueur-10') & (df_plot['nomSeance'] == 'Match')]['intensitemax'],
marker_color='#576DF3',
name='Matchs', opacity=1
)
fig.update_xaxes(
tickangle=45, dtick='L1'
)
fig.add_hline(
y=df_plot[df_plot['sportif'] == 'Joueur-10']['intensitemax'].median(),
line_width=1, line_dash='longdash'
)
fig.add_hline(
y=df_plot[df_plot['sportif'] == 'Joueur-10']['intensitemax'].quantile(0.75),
line_width=1, line_dash='dot'
)
fig.add_annotation(
dict(
font=dict(color="black",size=10), x=1.05,
y=df_plot[df_plot['sportif'] == 'Joueur-10']['intensitemax'].median()+0.1,
showarrow=False, text='<b>50%</b>', xref="paper", yref="y"
)
)
fig.add_annotation(
dict(
font=dict(color="mediumblue",size=10), x=1.05,
y=df_plot[df_plot['sportif'] == 'Joueur-10']['intensitemax'].quantile(0.75)+0.1,
showarrow=False, text='<b>75%</b>', xref="paper", yref="y"
)
)
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=14,
label='2w',
step='day'),
dict(count=1,
label='1m',
step='month'),
dict(count=2,
label='2m',
step='month'),
dict(count=6,
label='6m',
step='month'),
dict(count=1,
label='1y',
step='year'),
dict(step='all')
])
),
rangeslider=dict(
visible=True
),
type="date"
)
)
button1 = [dict(method = 'update',
args = [{'y': [df_plot[df_plot['sportif'] == 'Joueur-10'][c],
df_plot[(df_plot['sportif'] == 'Joueur-10') & (df_plot['nomSeance'] == 'Match')][c],
df_plot[df_plot['sportif'] == 'Joueur-10'][c].median(),
df_plot[df_plot['sportif'] == 'Joueur-10'][c].median()+0.1]
}],
label = c) for c in marqueurs]
button2 = [dict(method = 'update',
args = [{'y': [df_plot[df_plot['sportif'] == n]['intensitemax'],
df_plot[(df_plot['sportif'] == n) & (df_plot['nomSeance'] == 'Match')]['intensitemax'],
df_plot[df_plot['sportif'] == n]['intensitemax'].median(),
df_plot[df_plot['sportif'] == n]['intensitemax'].median()+0.1]
}],
label = n) for n in df_plot.sportif.unique()]
fig.update_layout(width=1000, height=800,
yaxis=dict(range=[0,10]),
template='plotly_white',
autosize=False,
updatemenus=[
dict(
buttons=button1,
active=0,
x=0.5, y=1.085,
xanchor='left', yanchor='top'
),
dict(
buttons=button2,
active=0,
x=0.3, y=1.085,
xanchor='left',
yanchor='top'
)
]
)
fig.show()
As you can see, I tried to code for one hline (the ‘median’ one). But when I select a new column or ‘sportif’ with my dropdwns the line stays the same.
And here is my fig:
Thanks all for your help