简体   繁体   English

plotly:有没有办法在添加辅助轴时禁用右轴?

[英]plotly: Is there a way to disable the right axis on adding a secondary axis?

When setting a figure's specs to have 'secondary_y'=True , it automatically adds a placeholder for an axis on the right of the figure.当将图形的规格设置为'secondary_y'=True时,它会自动为图形右侧的轴添加占位符。 Is there any way to make it go away or change the to span of the subplot?有没有办法让它 go 消失或改变子图的跨度?

In the following example see the differences in the right margin of the plot.在以下示例中,查看 plot 的右边距的差异。

在此处输入图像描述

For an easy reproduction:为了便于复制:

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

make_subplots(specs=[[{'secondary_y': True}]]).add_trace(go.Scatter(
    x=[1, 2, 3],
    y=[4, 5, 6],
    name="yaxis1 data"
))

Thanks!谢谢!

We can create fig1 and fig2 and look at their layout.我们可以创建fig1fig2并查看它们的布局。

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

fig1 = make_subplots(specs=[[{'secondary_y': True}]]).add_trace(go.Scatter(
    x=[1, 2, 3],
    y=[4, 5, 6],
    name="yaxis1 data"
))

fig2 = make_subplots().add_trace(go.Scatter(
    x=[1, 2, 3],
    y=[4, 5, 6],
    name="yaxis1 data"
))

When we look at the layout for each fig, the x-axis domain is different between the two:当我们查看每个图的布局时,两者的 x 轴域是不同的:

>>> fig1.layout['xaxis']['domain']
(0.0, 0.94)
>>> fig2.layout['xaxis']['domain']
(0.0, 1.0)

So we can set fig1 to have the same xaxis domain as fig2 :因此我们可以将fig1设置为与 fig2 具有相同的fig2域:

fig1.layout['xaxis']['domain'] = (0,1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM