Hi All,
I am creating subplots where in I need secondary y axis for the plot in 2nd row. Both plots are in same column.
I am getting the below ValueError:
ValueError:
The ‘specs’ argument to make_subplots must be a 2D list of dictionaries with dimensions (2 x 1).
Received value of type <class ‘list’>: [[{‘secondary_y’: True}, {‘secondary_y’: True}], [{‘colspan’: 1}, None]]
I believe that I am making some mistake in below line but not able to identify the mistake.
fig = make_subplots(rows=2, cols=1, print_grid=True,
specs=[[{"secondary_y": True}, {"secondary_y": True}],
[{"colspan": 1}, None]])
Below is the complete set of the code:
import talib as ta
import yfinance as yf
import pandas as pd
import plotly.io as pio
pio.renderers.default='browser'
import plotly.graph_objects as go
from plotly.subplots import make_subplots
'''
Extracting the data
'''
VIP = yf.Ticker('VIPIND.NS')
df = VIP.history(period="max")
df.reset_index(inplace = True)
df['Date'] = pd.to_datetime(df['Date'])
'''
Creating the technical indicators
'''
df['EMA_Close'] = ta.EMA(df.Close,100)
df['MA_Close'] = ta.MA(df.Close,60)
df['MACD'],df['MACDsig'],df['MACDhist']=ta.MACD(df.Close,30,60,15)
'''
###############################
Creating Plots
###############################
'''
'''
Declaring subplots
'''
fig = make_subplots(rows=2, cols=1, print_grid=True,
specs=[[{"secondary_y": True}, {"secondary_y": True}],
[{"colspan": 1}, None]])
'''
Plotting the first row with OHLC, EMA and MA lines
'''
fig.add_trace(go.Candlestick(x=df["Date"], open=df["Open"], high=df["High"],
low=df["Low"], close=df["Close"], name="OHLC",showlegend=True),
row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x=df['Date'], y=df['EMA_Close'], showlegend=True,
name="EMA Close",line=dict(color="firebrick")
), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x=df['Date'], y=df['MA_Close'], showlegend=True,
name="MA Close",line=dict(color="cornflowerblue")
), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x=df['Date'], y=df['MACDsig'], showlegend=True,
name="MACD Signal",line=dict(color="chocolate")
), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x=df['Date'], y=df['MACD'], showlegend=True,
name="MACD",line=dict(color="chartreuse")
), row=2, col=1,secondary_y=True)
fig.update(layout_xaxis_rangeslider_visible=False)
fig.update_layout(height=600, width=1100)
fig.update_layout(
title='OHLC and Volume',
yaxis_title='Prices (Rs)',
xaxis_title='Dates',
yaxis_tickformat='D')
fig.update_layout(template="plotly_white")
fig.update_layout(
margin=dict(l=20, r=20, t=40,b=20),)
# Providing desired Fonts for the plots
fig.update_layout(
font_family="Courier New",
font_color="blue",
title_font_family="Times New Roman",
title_font_color="red",
legend_title_font_color="green")
fig.update_layout(legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1
))
fig.show()
Requesting guidance in identifying the mistake I am making to resolve this error.
Regards
Sudhir