python - 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.
推荐阅读
- python - 为什么不同方法的不同行为
- regex - 在 htacces 中将正则表达式用于 Require 语句
- node.js - 如何在 Node.js 应用程序中处理向 Firestore 数据库添加多达 10 万个条目
- android - 从 android 中的 aws s3 服务器访问私有图像 url
- laravel - Laravel Passport:使用自定义用户名和密码创建令牌
- angular - 如何在 ngx-guided-tour 的弹出窗口中更改文本(和其他)?
- sql-server - SQL Server 错误日志增长过快。无法真正说出错误消息是关于什么的
- amazon-web-services - 如何在 Windows 10 上安装 aws iot greengrass
- typescript - 打字稿变量值不显示更新值
- laravel - Laravel Eloquent:动态地从一种方法转移到另一种方法