Second y axis does not plot

I have the following dataframe, named β€˜df’:

||Metered HVAC|Modeled HVAC|Metered CDD50|Metered HDD65|Modeled CDD50|Modeled HDD65|
| --- | --- | --- | --- | --- | --- | --- |
|Jan|10401.099725|8283.162493|0.000000|1114.895833|0.000000|978.416667|
|Feb|8808.750610|7366.424402|0.000000|981.458333|0.000000|887.875000|
|Mar|1355.250010|932.895866|0.000000|156.562500|0.000000|84.000000|
|Apr|2263.000350|2090.634179|0.000000|251.177083|100.291667|138.458333|
|May|3564.400690|4667.685194|585.020833|0.000000|617.000000|0.000000|
|Jun|4161.699885|4363.805553|705.864583|0.000000|682.333333|0.000000|
|Jul|7610.399970|4781.006695|907.687500|0.000000|852.750000|0.000000|
|Aug|5956.301000|4790.813234|939.583333|0.000000|758.208333|0.000000|
|Sep|4683.400600|3580.763217|712.000000|0.000000|479.625000|55.375000|
|Oct|5168.200650|3861.065892|276.687500|246.437500|37.583333|485.541667|
|Nov|7006.703280|5546.969078|0.000000|743.895833|0.000000|681.125000|
|Dec|7638.500180|6994.552075|0.000000|849.687500|0.000000|976.083333|

I’m trying to plot the first two columns as line traces with the first y axis, and the latter three columns as bars on a second y axis. This is my code:

traces = [
go.Scatter(x=df.index, y=df['Metered HVAC'].values, yaxis= 'y1'),
go.Scatter(x=df.index, y=df['Modeled HVAC'].values, yaxis= 'y1'),
go.Bar(x=df.index, y = df['Metered CDD50'].values, yaxis = 'y2'),
go.Bar(x=df.index, y = df['Metered HDD65'].values, yaxis = 'y2'),
go.Bar(x=df.index, y = df['Modeled CDD50'].values, yaxis = 'y2'),
go.Bar(x=df.index, y = df['Modeled HDD65'].values, yaxis = 'y2')
]
layout = go.Layout(legend={'orientation': 'h'},
                   yaxis1={'side': 'left'},
                   yaxis2={'side': 'right'})
                   
fig = go.Figure(traces, layout)
py.iplot(fig)

When I plot it, both y axes show up , but only the β€˜bars’ (yaxis2) traces are visible. I’ve looked online and tried switching up the yaxis formatting / labeling as well as using β€˜plot’ instead of β€˜iplot’, but no luck. Am I doing something wrong?

Thanks!

Hi @Msweeney,

I think you need to add overlaying='y' to the specification of yaxis2. See https://plot.ly/python/multiple-axes/#two-y-axes for example.

Hope that helps!
-Jon