gpt4 book ai didi

plotly :次要 y 轴导致右侧空白

转载 作者:行者123 更新时间:2023-12-03 20:49:48 39 4
gpt4 key购买 nike

我正在绘制一个包含大量超高分辨率数据的绘图虚线图。在添加第二个 y 轴时,我发现在 plotly svg 组件内的图表右侧出现一个空白区域。当我关闭第二个轴时,那个空白空间消失了。当图表在整个屏幕上最大化时,可以很好地看到。
作为展示,我使用了 plotly 文档中的一个示例:

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()
它产生以下图表,不再居中:
empty_space_on_the_right
我怎样才能摆脱那个空的空间?

最佳答案

您可以在 fig.update_layout() 中指定边距.我将右边距设置为 0。
您还可以调整顶部、底部和左边距。
例如margin = dict(l=50, r=50, b=50, t=50)

# Add figure title
fig.update_layout(
title="Right margin",
showlegend=False,
margin=dict(r=0)
)
enter image description here

关于 plotly :次要 y 轴导致右侧空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63523328/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com