Hello,
I m working on a python project with yfinance library, there is no problem with one x-y axis, but when I try to add secondary y axis I get this error:
ValueError:
Invalid value of type ‘builtins.str’ received for the ‘x’ property of scatter
Received value: ‘Date’
The 'x' property is an array that may be specified as a tuple,
list, numpy array, or pandas Series
Any help? thanks from advance
Here is my code:
import yfinance as yf
import plotly.graph_objects as go
colors = {
‘background’: ‘#f5f5f5’,
‘text’: ‘#000000’
}
def get_stock_price_fig(df):
fig = make_subplots(specs=[[{“secondary_y”: True}]])
fig.add_trace(
go.Line(df, x=‘Date’, y=‘Close’,template=“plotly_white”),
secondary_y=True
)
fig.add_trace(
go.Bar(df, x=‘Date’, y=‘Volume’),
secondary_y=True
)
fig.update_layout(
plot_bgcolor=colors['background'],
paper_bgcolor=colors['background'],
font_color=colors['text']
)
fig.update_xaxes(
rangeslider_visible=False,
rangeselector=dict(
buttons=
list([
dict(count=14, label="2w", step="day", stepmode="backward"),
dict(count=30, label="1m", step="day", stepmode="backward"),
#dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all",stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="todate")
]
)
))
fig.update_xaxes(showgrid=True)
#fig.update_xaxes(showgrid=True, tickfont_family="Arial Black")
fig.update_yaxes()
return fig