I'm trying to plot the daily price and the total number of bid and ask orders per day for a typical stock on the same figure.
Here is what I've done so far, but I think there is a more efficient way to create the same plot using Plotly.
import pandas as pd
import plotly.graph_objects as go
# Create the base figure
fig = go.Figure()
# Add a line graph
fig.add_trace(
go.Scatter(x=df.index, y=df['price'], name='Daily Price'))
# Create financial buttons
fin_buttons = [
{'count': 7, 'label': "1WTD", 'step': "day", 'stepmode': "todate"},
dict(count=7, label="1W", step="day", stepmode="backward"),
{'count': 1, 'label': "1MTD", 'step': "month", 'stepmode': "todate"},
dict(count=1, label="1M", step="month", stepmode="backward"),
{'count': 3, 'label': "3MTD", 'step': "month", 'stepmode': "todate"},
dict(count=3, label="3M", step="month", stepmode="backward"),
{'count': 6, 'label': "6MTD", 'step': "month", 'stepmode': "todate"},
dict(count=6, label="6M", step="month", stepmode="backward"),
{'count': 1, 'label': "YTD", 'step': "year", 'stepmode': "todate"},
{'count': 1, 'label': "1Y", 'step': "year", 'stepmode': "backward"},
dict(step="all")
]
# Create the date range buttons & show the plot
fig.update_layout({'xaxis': {'rangeselector': {'buttons': fin_buttons}}})
fig.update_layout(yaxis=dict(autorange=True))
# Add bar chart
fig.add_trace(
go.Bar(name='Bids',
x=df.index,
y=df['bid']))
# Add bar chart
fig.add_trace(
go.Bar(name='Asks',
x=df.index,
y=-df['ask']))
# Show the plot
fig.show()
The problem is autorange
property does not rescale the y-axis. In other words, when I click a time button, the y-axis for the price line chart does not automatically reset!