✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Y-axis is "moved up" when using add_trace()

For some reason, the y-axis is “moved up” (see figure 1 vs. figure 2) when I add the second plot to the figure.

My code looks like this (I only copy the code for the main y-axis… I didn’t copy the code for secondary_y)

    fig = make_subplots(specs=[[{'secondary_y': True}]])
    
    fig.add_trace(go.Bar(name='Daily New Cases',
                        x=data.date,
                        y=data.new_cases,
                        marker_color='darkblue'))

     fig.add_trace(go.Scatter(
                    x=data.date, 
                    y=data.new_cases_SMA7,
                    mode='lines', line=dict(
                        width=3, color='rgb(100,140,240)'
                    ),
                    name='7 days Moving Average'))

Hi @tud7, yes the axis range is chosen so that all values of the trace can be seen, therefore for a scatter trace the axis has to start below 0 so see the values at 0. You can set the range of the axis manually.