Hi, I figured out that rendering a figure with subplots and with at least one subplot with only a secondary y axis and not a primary one, it creates a display bug. Hereโs a code reproducing it :
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Create subplots: 1 column, 3 rows, with the second subplot having a secondary y-axis
fig = make_subplots(
rows=3, cols=1,
shared_xaxes=True,
vertical_spacing=0.1,
subplot_titles=("Primary Y-Axis Plot", "Secondary Y-Axis Plot", "Another Primary Y-Axis Plot"),
specs=[[{}], [{'secondary_y': True}], [{}]] # Define the secondary_y for the second subplot
)
# Add first plot (e.g., scatter plot)
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[4, 5, 6], mode='lines+markers', name='Scatter 1'),
row=1, col=1
)
fig.add_trace(
go.Scatter(x=['A', 'B', 'C'], y=[10, 20, 30], mode='lines', name='Line 1'),
row=2, col=1,
secondary_y=True # secondary y-axis
)
# Add third plot (e.g., line plot)
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[2, 4, 8], mode='lines', name='Line 2'),
row=3, col=1
)
# Update layout
fig.update_layout(
height=800,
width=600,
title_text="Subplots with Secondary Y-Axis",
showlegend=True
)
# Update y-axis titles for secondary y-axis subplot
fig.update_yaxes(title_text="Primary Y-Axis", row=2, col=1)
fig.update_yaxes(title_text="Secondary Y-Axis", row=2, col=1, secondary_y=True)
fig.show()