代码之家  ›  专栏  ›  技术社区  ›  Zachary Brasseaux

Python Plotly y轴范围与子图不匹配,不允许我手动定义它们

  •  0
  • Zachary Brasseaux  · 技术社区  · 1 年前

    Two Plotly Scatter Plots combined in one subplot

    在我的Plotly子图中,上图的范围为[0,10],而下图的范围为[0.14]。SO上关于此的其他问题( Plotly: How to change the range of the y-axis of a subplot? )建议使用以下内容:

    fig.update_layout(yaxis = dict(range=[0, 14]))
    fig.update_layout(yaxis2 = dict(range=[0, 14]))
    

    这并没有解决问题。它不会导致任何错误,但也不能解决我的问题。我需要它们具有相同的范围,以便正确地显示两者之间的差异。

    我尝试过手动调整刻度,但找不到允许定义刻度数或手动将刻度添加到y轴的值。

    感谢您的帮助。

    1 回复  |  直到 1 年前
        1
  •  2
  •   David Harris    1 年前

    如果您希望所有y轴都具有相同的范围,请尝试以下操作:

    fig = make_subplots(rows=2, cols=1, shared_yaxes='all')
    

    https://plotly.com/python-api-reference/generated/plotly.subplots.make_subplots.html