Plotly:如何格式化文本(下划线、粗体、斜体)
Plotly: How to format text (underline, bold, italic)
我尝试在使用注释时在 plotly 中为文本加下划线。
我使用
添加注释
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
是否有一个选项(在注释字典中,也许?)有下划线的文本?
谢谢!
Plotly 使用 HTML 标签的子集来格式化文本,例如粗体 '<b></b>'
和斜体 '<i></i>'
。唉,'<u></u>'
目前好像没有包含在内。但是换行符 是 包括在内,因此您可以像这样进行一些变通:
string = "These are orange"
myText = string+'<br>'+ '-'*len(string)
剧情:
代码:
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.
我尝试在使用注释时在 plotly 中为文本加下划线。 我使用
添加注释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
是否有一个选项(在注释字典中,也许?)有下划线的文本?
谢谢!
Plotly 使用 HTML 标签的子集来格式化文本,例如粗体 '<b></b>'
和斜体 '<i></i>'
。唉,'<u></u>'
目前好像没有包含在内。但是换行符 是 包括在内,因此您可以像这样进行一些变通:
string = "These are orange"
myText = string+'<br>'+ '-'*len(string)
剧情:
代码:
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.