Plotly subplots are not working and received TypeError: 'module' object is not callable

Good Evening my beloved plotly dash community members
I have been trying to plot unemployment rate along with changes with plotly make_subplots but I received Type Error: ‘module’ object is not callable , I have looked through the documentation for answers I did not find an answer for this problem ,neither in the documentation nor in historical topics in plotly dash community please help me solve this problem
with best regards

I think you should add your dataframe and code, not picture :smiley:

1 Like

@hoatran you mean I should send you the code itself ? cos I did not get what you mean

and this the code :slight_smile:

subplot for unemployment rate with changes over years

df_unemplo=pd.read_excel(“unemployment data KSA.xlsx”)
df_unemplo.columns=df_unemplo.columns.str.replace(" “,”")
df_unemplo[‘date’]=pd.to_datetime(df_unemplo[‘date’], format=‘%Y’)
fig4=make_subplots(rows=2,cols=1,shared_xaxes=True, vertical_spacing=0.03,
subplot_titles=(‘Unemployment Rate’,‘Changes’),
row_heights=[0.2,0.7] )


fig4.update_layout(title=‘Unemployment Rate From 1970 until 1992 ‘,
hovermode=‘x unified’, plot_bgcolor=’#000000’,
fig4.add_trace(, x=df_unemplo[‘date’],y=df_unemplo[‘AnnualChange’]),row=2,col=1)
with best regards dear @hoatran

1 Like

Yep you can upload your df to somewhere and we can download it to try to run.

I uploaded the excel sheet in a publicly sharable google drive
unemployment data KSA.xlsx - Google Sheets
have a look at it
with best regards @hoatran

I see some problem in your code as below:

  • You have to use go.Scatter not go.scatter; go.Bar not
  • You need to delete df_unemplo in go.Bar

This is worked code:

fig4=make_subplots(rows=2,cols=1,shared_xaxes=True, vertical_spacing=0.03,
subplot_titles=('Unemployment Rate','Changes'),
row_heights=[0.2,0.7] )
fig4.add_trace(go.Scatter(x=df_unemplo['date'],y=df_unemplo[' Unemployment Rate (%)']),row=1,col=1)
fig4.update_layout(title='Unemployment Rate From 1970 until 1992',
                   hovermode='x unified', plot_bgcolor='#000000',
fig4.add_trace(go.Bar(x=df_unemplo['date'],y=df_unemplo[' Annual Change']),row=2,col=1)

Thank you very Much Indeed dear @hoatran

one final question though I have added buttons to the chart but It appeared on both plots how can I turn it off from the second below bar plot whilst retaining it on the above one with control on both ? dear @hoatran

Hm not sure about it. I’m thinking about using dropdown with Dash.

may be a feasible option but I just want to remove it from the below chart
any ways thank you

I solved it by : fig4.update_traces(xaxis=“x2”)
thanks bro @hoatran

1 Like