以下跟踪在绘图中显示了一些文本。我想将此文本旋转到 90\xc2\xb0。我尝试了textangle关键字,但不起作用。
trace = go.Scatter(\n x=[1999],\n y=[1],\n mode='text',\n name='Note',\n text=['Missing data due to database change'],\n textposition='middle center'\n)\nRun Code Online (Sandbox Code Playgroud)\n
今天正好遇到这个问题。该方法在 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()
Run Code Online (Sandbox Code Playgroud)
在这里了解更多: https: //plotly.com/python/text-and-annotations/
| 归档时间: |
|
| 查看次数: |
3067 次 |
| 最近记录: |