[英]How to add text on a bubble chart with plotly
我正在使用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)
問題在於這里沒有顯示任何單詞。 如何更改代碼以使其可視化?
謝謝,
我從這個網站上舉了一個例子,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參數: mode ='markers + text'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.