繁体   English   中英

如何在情节跟踪中旋转文本?

[英]How to rotate text in a plotly trace?

以下跟踪在绘图图中显示了一些文本。 我想将此文本旋转到 90°。 我尝试了textangle关键字,但这不起作用。

trace = go.Scatter(
    x=[1999],
    y=[1],
    mode='text',
    name='Note',
    text=['Missing data due to database change'],
    textposition='middle center'
)

今天遇到这个问题。 该方法适用于 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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM