Plotly/Dash:是否可以隐藏次要 y 轴的刻度标签?

Plotly/Dash: is it possible to hide tick labels of a secondary y axis?

我想从我的辅助 y 轴上删除刻度标签,同时保留主 y 轴上的刻度标签。

    fig.add_trace(go.Scatter(x=df.index, y=df['A'],
                             line=dict(color='rgba(255, 255, 0, 0.25)', width=1)), secondary_y=False, row=1, col=1)
    fig.add_trace(go.Scatter(x=df.index, y=df['B'],
                             line=dict(color='rgba(128, 75, 183, 0.5)', width=1)), secondary_y=True, row=1, col=1)
    fig.update_yaxes(showticklabels=True, row=1, col=1, secondary_y=False)

以上没有解决问题,因为次要 y 轴的刻度标签仍然可见。

有什么想法吗?

您可以使用:

fig.layout.yaxis2.update(showticklabels=False)

并得到:

否则你会产生:

完整代码:

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

# 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_text="Double Y Axis Example"
)

# 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.layout.yaxis2.update(showticklabels=False)

fig.show()