简体   繁体   English

如何使用plotly在气泡图上添加文本

[英]How to add text on a bubble chart with plotly

I am doing a Bubble chart with python using plotly. 我正在使用plotly用python做一个气泡图。 I want to visualize word frequencies. 我想形象化单词频率。 So I have made two columns with 5 bubbles and I would like to write the word inside each bubble. 所以我做了两列带有5个气泡的列,我想在每个气泡内写一个词。 My code is: 我的代码是:

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)

The problem is that no word is showed here. 问题在于这里没有显示任何单词。 How to change the code to visualize them? 如何更改代码以使其可视化?

Thank you, 谢谢,

I toook the example from this website Text and Annotations in Plotly 我从这个网站上举了一个例子,Plotly中的文字和注释

I believe your 'mode' parameter is not accurate. 我相信您的“模式”参数不正确。

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'
                   )

So you should write in the mode parameter: mode='markers+text' 因此,您应该输入mode参数: mode ='markers + text'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM