如何调整y轴的步长

问题描述 投票:0回答:0

我有一个图,其中有两个 y 轴。左边的y轴代表条形图,左边的y轴代表两条线。问题是左侧 y 轴当前为 y 轴值创建单独的步长,这导致左侧出现额外的 y 轴线。我希望左侧 y 轴与右侧 y 轴上的刻度线对齐,以便 y 轴线匹配,这应该会自动进行(这样也很容易将绘图用于其他数据帧)。如何做到这一点?

import plotly.graph_objects as go

bar_trace = go.Bar(x=line_df['Year/Quarter'], y=line_df['CUR (€)'], name='CUR (€)')

line_trace1 = go.Scatter(x=line_df['Year/Quarter'], y=line_df['CUR PP'], name='CUR PP', 
                 yaxis='y2', mode='lines+markers', line=dict(color='orange'))

line_trace2 = go.Scatter(x=line_df['Year/Quarter'], y=line_df['CUR PP'], name='CUR PP', 
                 yaxis='y2', mode='lines+markers', line=dict(color='red'))

layout = go.Layout(title='test', 
           yaxis=dict(title='test'), 
           yaxis2=dict(title='test', overlaying='y', side='right'))

fig = go.Figure(data=[bar_trace, line_trace1, line_trace2], layout=layout)

fig.show()

python plotly visualization yaxis plotly.graph-objects
© www.soinside.com 2019 - 2024. All rights reserved.