Plotly 论文格式不统一

Plotly paper formatting is not uniform

我正在使用 Plotly 中的注释系统来注释图形的轴。我在绘图中使用“纸张”设置指定坐标。但是,我注意到纸张坐标在图形中并不总是统一的,至少在关闭箭头时是这样。有谁知道为什么会这样?这里我提供代码给大家看:

def test():
    
    fig = go.Figure()

    ylabels = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    annotations = []
    for i, label in enumerate(ylabels):
        print(label/100)
        annotations.append(
            dict(
                yref = 'paper',
                y = label/100, x = 0,
                text = ylabels[1],
                showarrow = False,
                yshift = 0,
            )
        )
    fig.update_layout(
        annotations = annotations,
        yaxis = dict(
            showticklabels = False,
            tickvals = ylabels,
            range = [0, 100]
        ),
        xaxis = dict(
            showticklabels = False
        )
    )
    fig.show()

Non-uniform spacing when arrows are off

出于某种原因,这与关闭箭头有关。当箭头打开时,它们在 x 轴上均匀分布。

Uniform spacing when arrows are on

问题似乎可以通过将 yanchor 设置为 topmiddlebottom 来解决,请参阅 Plotly documentation

import plotly.graph_objects as go

fig = go.Figure()

ylabels = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

annotations = []
for i, label in enumerate(ylabels):
    annotations.append(
        dict(
            yref='paper',
            y=label / 100,
            x=0,
            text=ylabels[1],
            showarrow=False,
            yshift=0,
            yanchor='middle' # default is 'auto'
        )
    )
    
fig.update_layout(
    annotations=annotations,
    yaxis=dict(
        showticklabels=False,
        tickvals=ylabels,
        range=[0, 100]
    ),
    xaxis=dict(
        showticklabels=False
    )
)

fig.show()