Finance line chart with custom time buttons
You have been engaged by an Excel-savvy finance trading company to help them jazz up their data visualization capabilities. Safe to say, Excel graphics aren't cutting it for them!
The fund is particularly interested in a pharmaceutical company and how it has performed this year and wants a tool to help them zoom in on key timeframes.
In this exercise, you will help the trading company by visualizing the opening stock price of the company over 2020 and creating the following date-filter buttons:
- 1WTD = The previous week (7 days to date)
- 6MTD = The previous 6 months week (6 months to date)
- YTD = The current year to date
You have a stock_price DataFrame available that contains the necessary data.
Questo esercizio fa parte del corso
Introduction to Data Visualization with Plotly in Python
Istruzioni dell'esercizio
- Create a line chart of the
stock_priceDataFrame using theDateandOpencolumns. - Create a list called
fin_buttonscontaining the custom date-filter buttons mentioned above. - Update the figure using
.update_layout()to construct buttons using your created list.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Create a line chart
fig = px.____(stock_price, x='____', y='____', title='Opening Stock Prices')
# Create the financial buttons
fin_buttons = [
{'count': ____, 'label': "1WTD", 'step': "____", 'stepmode': "todate"},
{'count': ____, 'label': "6MTD", 'step': "____", 'stepmode': "todate"},
{'count': ____, 'label': "YTD", 'step': "____", 'stepmode': "todate"}
]
# Add the buttons
fig.update_layout(dict(
xaxis=dict(
____=dict(buttons=____)
)))
fig.show()