绘图:如何设置文本格式(下划线、粗体、斜体)

2024-09-28 03:16:55 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用注释时,我会尝试在文本中绘出下划线。 我使用

import plotly.graph_objects as go
g = go.FigureWidget(make_subplots(rows=1,cols=1))
g.update_layout(annotations=[dict(text='my text')]) #plus any other parameters

是否有一个选项(在注释目录中,可能?)来添加下划线文本

谢谢


Tags: text文本importgomakeobjectsasupdate
1条回答
网友
1楼 · 发布于 2024-09-28 03:16:55

Plotly使用HTML标记的子集格式化文本,如粗体'<b></b>'和斜体'<i></i>'。唉,'<u></u>'目前似乎没有包括在内。但是linebreak包含在中,因此您可以像这样做一些工作:

string = "These are orange"
myText = string+'<br>'+ '-'*len(string)

绘图:

enter image description here

代码:

import plotly.graph_objects as go
animals=['giraffes', 'orangutans', 'monkeys']

fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])])

string = "These are orange"
myText = string+'<br>'+ '-'*len(string)

fig.update_layout(annotations=[dict(x='orangutans',y = 15, text=myText, font=dict(family='Courier New, monospace'))])
fig.show()

绘图来源:使用help(fig.layout)

  text
 |                  Sets the text associated with this annotation.
 |                  Plotly uses a subset of HTML tags to do things
 |                  like newline (<br>), bold (<b></b>), italics
 |                  (<i></i>), hyperlinks (<a href='...'></a>).
 |                  Tags <em>, <sup>, <sub> <span> are also
 |                  supported.

相关问题 更多 >

    热门问题