ValueError When Using Secondary Axes In Plotly- Invalid property specified for object of type plotly.graph_objs.Scatter: 'secondary_y'

Hello everybody, need some help. I’m a beginner, so this might be a silly question. I was attempting to plot a graph with secondary axes in plotly, here’s my code -

f = make_subplots(specs=[[{“secondary_y”: True}]])
f.add_trace(go.Scatter(
y = df_totalfires.loc[:, ‘1998’ : ‘2000’].sum(axis = 0),
x = df_totalfires.columns[:3],
secondary_y = False

))

f.addtrace(go.Scatter(
y = brazil_rainfall.loc[1998:2000, :].sum(axis = 1),
x = df_totalfires.columns[:3],
secondary_y = True

))

This is giving me the traceback error:

ValueError: Invalid property specified for object of type plotly.graph_objs.Scatter: ‘secondary_y’

Am I doing something wrong here? Any help would be appreciated. Thank you so much!

Hi @srijon,

the arguments for f.add_trace() are as follows:

f.add_trace(trace_definition, secondary_y=False),
but in your call of f.add_trace() you inserted secondary_y as a keyword in go.Scatter().

The right code:

f.add_trace(go.Scatter(
                 y = df_totalfires.loc[:, ‘1998’ : ‘2000’].sum(axis = 0),
                 x = df_totalfires.columns[:3]), #I INSERED HERE a )
            secondary_y = False)

and analogously when adding the second trace.

1 Like

Ahhh I get it. Thank you so much!

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online