✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

The secondary y-axis does not appear on the subplots

Hi,

I have 2 stacked subplots, in which the heatmap is shown on the top while the line plots with multiple y-axes shown at the bottom. I have a very difficult time figuring out why the secondary y-axis does not show on the right. Another y-axis on the right suppose to show up but it doesn’t. I have searched through the forum and elsewhere and have tried different ways to see if I can resolve it. Unfortunately, I still can’t. Would any of you help me out with this? I would really appreciate it.

Below is my code:

import plotly.graph_objects as go
import plotly.express as px
from plotly.offline import download_plotlyjs, init_notebook_mode,  plot
from plotly.subplots import make_subplots

import pandas as pd

# load dataset

# Create figure
# fig = go.Figure()


z=data.values
x=data.columns
y=data.index

fig = make_subplots(rows=2, cols=1, 
                    shared_xaxes=True, 
                    # column_widths=[0.9,0.1],
                    row_heights=[0.85,0.15],
                    vertical_spacing=0.02,
                    specs=[[{"secondary_y": False}],
                            [{"secondary_y": True}]]
                    
                    )

# Add surface trace
# fig.add_trace(go.Heatmap(z=df.values.tolist(), colorscale='Rainbow'))

fig.add_trace(go.Heatmap(   z=z,
                            x=x,
                            y=y,
                            
                            type='heatmap',
                            colorscale='Jet' ,
                            zmin=-10,zmax=10,
                            yaxis='y',
                            # xaxis='x',
                            colorbar={'len':0.5, 'y':0.7}
                        )
              
             )



fig.add_trace(go.Scatter(
                            x=pump_data['Time'],
                            y=pump_data['SLUR'],
                            yaxis='y2',
                            xaxis='x2',
                            showlegend=False


                            
                            ),
                            row=2,col=1,
                            secondary_y=False,

                            # name='TR_PRESS',
                            # yaxis='y1'
                            )

fig.add_trace(go.Scatter(
                            x=pump_data['Time'],
                            y=pump_data['PPA'],
                            yaxis='y3',
                            xaxis='x2',

                            showlegend=False

),
                            row=2,col=1,
                            secondary_y=False,

                            # name='TR_PRESS',
                            # yaxis='y1'
                            )

fig.add_trace(go.Scatter(
                            x=pump_data['Time'],
                            y=pump_data['TR_PRESS'],
                            yaxis='y4',
                            # xaxis='x2',
                            showlegend=False

                        ),
                            row=2,col=1,
                            secondary_y=True
                            # name='TR_PRESS',
                            
                            
            )

# Update plot sizing
fig.update_layout(
    width=800,
    height=900,
    autosize=False,
    margin=dict(t=100, b=0, l=0, r=0),
)

# Update 3D scene options
fig.update_scenes(
    aspectratio=dict(x=1, y=1, z=0.7),
    aspectmode="manual"
)

# Add drowdowns
button_layer_1_height = 1.08
fig.update_layout(
    xaxis1=dict(
        domain=[0.15, 0.95]
    ),
    
    xaxis2=dict(
        domain=[0.15, 0.95]
    ),
    
   
     
    yaxis=dict(
        autorange='reversed'
        ),
    
    # yaxis2=dict(
    #     autorange=True
    #     ),

    yaxis2=dict(
        title="SLUR",
        # autorange=True,
        titlefont=dict(
            color="#d62728"
        ),
        tickfont=dict(
            color="#d62728"
        ),

    ),
    
     yaxis3=dict(
        title="PPA",
        autorange=True,
        titlefont=dict(
            color="#9467bd"
        ),
        tickfont=dict(
            color="#9467bd"
        ),
        anchor="free",
        overlaying="y2",
        side="left",
        position=0.05
    ), 
    
    yaxis4=dict(
        title="TR_PRESS",
        autorange=True,
        titlefont=dict(
            color="#9467bd"
        ),
        tickfont=dict(
            color="#9467bd"
        ),
        
        anchor='free',
        overlaying="y2",
        side="right",
        position=1
    
    ), 
    
    updatemenus=[
        dict(
            buttons=list([
                dict(
                    args=["colorscale", 'Jet'],
                    label='Jet',
                    method="restyle"
                ),
                dict(
                    args=["colorscale", 'Rainbow'],
                    label='Rainbow',
                    method="restyle"
                ),
                dict(
                    args=["colorscale", "Bluered"],
                    label='Seismic',
                    method="restyle"
                ),
                dict(
                    args=["colorscale", "Greens"],
                    label="Greens",
                    method="restyle"
                ),
            ]),
            direction="down",
            pad={"r": 10, "t": 10},
            showactive=True,
            x=0.1,
            xanchor="left",
            y=button_layer_1_height,
            yanchor="top"
        ),
        
        
         dict(
            buttons=list([
                
                dict(
                    args=["type", "heatmap"],
                    label="Heatmap",
                    method="restyle"
                ),
                                
                dict(
                    args=["type", "surface"],
                    label="3D Surface",
                    method="restyle"
                ),

            ]),
            direction="down",
            pad={"r": 10, "t": 10},
            showactive=True,
            x=0.8,
            xanchor="left",
            y=button_layer_1_height,
            yanchor="top"
        ),
         
        
    ]
)

fig.update_layout(
    annotations=[
        dict(text="colorscale", x=0, xref="paper", y=1.06, yref="paper",
                             align="left", showarrow=False),
        # dict(text="Reverse<br>Colorscale", x=0.25, xref="paper", y=1.07,
        #                      yref="paper", showarrow=False),
        # dict(text="Lines", x=0.54, xref="paper", y=1.06, yref="paper",
        #                      showarrow=False)
    ])

plot(fig)