如何在Plotly图表中旋转文本?

5
以下跟踪显示了图中的一些文本。我想将这个文本旋转90°。我尝试使用textangle关键字,但无效。
trace = go.Scatter(
    x=[1999],
    y=[1],
    mode='text',
    name='Note',
    text=['Missing data due to database change'],
    textposition='middle center'
)

1
嗨@Soren,你找到解决方案了吗?我遇到了完全相同的挑战! - MWB
1个回答

0
今天遇到了这个问题。这种方法在R中有效,但不确定Python是否适用。幸运的是,有多种方法可以向绘图添加文本。我成功地使用注释来解决了这个问题...
fig = make_subplots(rows=1, cols=1) # instantiate fig
x, y = [1999], [1] # vars
# create scatter
fig.add_trace(
    go.Scatter(
            x=x,
            y=y,
            mode='markers',
            name='Name',
        )
# create annotations iteratively for each var
for c, val in enumerate(x): ## count, val
    fig.add_annotation(
        x=x[c], 
        y =y[c],
        text=['text'],
        showarrow=False,
        align='center',
        textangle=-45,
        yanchor='bottom', 
        font=dict(color='rgb(255,0,0)', size=10))
        
fig.update_layout(
title_text="Title",
title_font_size=20,
font_size=16,
title_x=0.06,
showlegend=True,
legend_font_size=12,
height=600,
width=1200,
template='simple_white',
)

fig.show()

点击此处了解更多信息:https://plotly.com/python/text-and-annotations/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接