Introduction to Data Visualization with Plotly in Python
Alex Scriven
Data Scientist
A dictionary with a few key elements:
label
= text to appear on the buttoncount
= how many step
s to take when clicking the buttonstep
= what date period to move ('month'
, 'year'
, 'day'
)stepmode
= Either 'backward'
or 'todate'
'backward'
= moves straight back by the number of count
s'todate'
= like 'backward'
, but rounded to the start of the next full time period
count=6
, step='month'
):stepmode='backward'
would zoom the plot to start on April 20th (6 months backward)stepmode='todate'
would zoom the plot to start on May 1st (start of the following month to April 20th)
date_buttons = [ {'count': 6, 'step': "month", 'stepmode': "todate", 'label': "6MTD"},
{'count': 14, 'step': "day", 'stepmode': "todate", 'label': "2WTD"} ]
fig = px.line(data_frame=rain, x='Date', y='Rainfall', title="Rainfall (mm) in Sydney")
fig.update_layout(dict( xaxis=dict( rangeselector=dict(buttons=date_buttons) ))) fig.show()
Clicking the 2WTD button:
Clicking the 6MTD button:
Introduction to Data Visualization with Plotly in Python