I'm working on a plotly dash chart with lots of data that runs on ultra high res. On adding the second y-axis, I discovered, that an empty space appears on the right of the chart inside of the plotly svg component. That empty space vanishes when I turn off the second axis. It can be seen very well, when the chart is maximized over the entire screen.
As a showcase I used an example from the plotly documentation:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Add traces
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[40, 50, 60], name="yaxis data"),
secondary_y=False,
)
fig.add_trace(
go.Scatter(x=[2, 3, 4], y=[4, 5, 6], name="yaxis2 data"),
secondary_y=True,
)
# Add figure title
fig.update_layout(
title="Right margin",
showlegend=False
)
# Set x-axis title
fig.update_xaxes(title_text="xaxis title")
# Set y-axes titles
fig.update_yaxes(title_text="<b>primary</b> yaxis title", secondary_y=False)
fig.update_yaxes(title_text="<b>secondary</b> yaxis title", secondary_y=True)
fig.show()
It yields the following chart, not being centered any more:
How can I get rid of that empty space?
