python - 如何使用 plotly 在气泡图上添加文本
问题描述
我正在使用 python 绘制气泡图。我想可视化词频。所以我做了两列有 5 个气泡,我想在每个气泡内写下这个词。我的代码是:
trace0 = go.Scatter(
x=[1, 1, 1, 1, 1],
y=[1, 2, 3, 4, 5],
mode='markers',
text=['plant', 'use', 'student', 'show', 'water'], #words I want to show
textposition='top center',
marker=dict(
size=norm,
color=['rgb(255, 144, 14)','rgb(255, 144, 14)','rgb(255, 144, 14)', 'rgb(255, 144, 14)',
'rgb(255, 144, 14)'],
)
)
trace1 = go.Scatter(
x=[2, 2, 2, 2, 2],
y=[1, 2, 3, 4, 5],
mode='markers',
text=['use', 'water', 'diagram', 'show', 'plant'], #words I want to show
textposition='top center',
marker=dict(
size=norm,
color=['rgb(93, 164, 214)','rgb(93, 164, 214)','rgb(93, 164, 214)','rgb(93, 164, 214)','rgb(93, 164, 214)'],
)
)
data = [trace0,trace1]
py.iplot(data, filename='bubblechart-size', layout=layout)
问题是这里没有显示任何单词。如何更改代码以可视化它们?
谢谢,
解决方案
我从这个网站上的例子Text and Annotations in Plotly
我相信您的“模式”参数不准确。
trace2 = go.Scatter(
x=[0, 1, 2],
y=[2, 2, 2],
mode='markers+text',
name='Markers and Text',
text=['Text D', 'Text E', 'Text F'],
textposition='bottom center'
)
所以你应该在模式参数中写:mode='markers+text'
推荐阅读
- python - CommentedMap.update() 不保留评论
- c# - 版本 12+ 中是否有 Azure.Storage.Queue 的 ContinuationToken
- python - Jupyter Notebook Password Hash 出来很奇怪?
- android - 如何从 Google Cloud 获取 p12 文件(key.p12)?
- qt - 滚动时我的列表视图中的这些故障是什么?
- python - 如何使用脚本从 truecaller 中取消列出(删除)号码?
- drupal - 使用 composer 更新 drupal 会导致需求错误
- git - Github - 将工件提交到存储库
- r - 替换R中数据框中的值
- powershell - Powershell 脚本 - 返回 SSRS 报告名称、路径和连接字符串