密谋:如何设置文本格式(下划线,粗体,斜体) [英] Plotly: How to format text (underline, bold, italic)

查看:125
本文介绍了密谋:如何设置文本格式(下划线,粗体,斜体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用批注时,我会尝试在文本上加下划线. 我使用

I try to underline text in plotly when using annotations. I add my annotations using

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

是否有选项(可能在注释字典中?)带有下划线的文本?

Is there an option (in the annotations dict, maybe?) to have underlined text?

谢谢!

推荐答案

Plotly使用HTML标签的子集来设置文本格式,例如粗体'<b></b>'和斜体'<i></i>'. <,目前似乎未包括'<u></u>'.但是包含了换行符 ,因此您可以进行以下一些变通方法:

Plotly uses a subset of HTML tags to format text like bold '<b></b>' and italics '<i></i>'. Alas, '<u></u>' does not seem to be included at the moment. But linebreak is included, so you could make a little work-around like this:

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)密谋来源::

Plotly source: using 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.

这篇关于密谋:如何设置文本格式(下划线,粗体,斜体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆