plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.9k stars 2.53k forks source link

secondary_y creates a small spacing on the right #3210

Open ysmu opened 3 years ago

ysmu commented 3 years ago

It looks like secondary_y would cause the chart to render a small chunk of whitespace to the right of it.

With secondary_y:

image

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(specs=[[{'secondary_y': True}]])

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)

fig.update_layout(legend={'y': 1, 'x': 0}, margin={'t': 0, 'b': 0, 'l': 0, 'r': 0})
fig.show()

Without secondary_y:

image

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots()

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[40, 50, 60], name='yaxis data'))
fig.add_trace(go.Scatter(x=[2, 3, 4], y=[4, 5, 6], name='yaxis2 data'))

fig.update_layout(legend={'y': 1, 'x': 0}, margin={'t': 0, 'b': 0, 'l': 0, 'r': 0})
fig.show()
AaronStiff commented 1 year ago

@nicolaskruchten

It would break a few subplot tests, but changing max_width in _subplots to 1.0 instead of 0.94 seems to fix this.

https://github.com/plotly/plotly.py/blob/2b6ec1e16bebe260dfc673db869805f7ceb86e00/packages/python/plotly/plotly/_subplots.py#L573-L581

Is 0.94 arbitrary? Or is there a reason for the extra space? I've tested several subplots with max_width set to 1.0 and the secondary y-axis labels or title never get cut off.