2017-05-07 7 views
1

私は、プロットバブルチャートにpythonでテキストを追加する必要があります。私はデータ属性ごとに1つの値を取るためにテキスト属性を得ることができます。しかし、データポイントごとに、そのサイズと別の値の2つの値をツールチップに表示する必要があります。私はリストのリストを使用していますが、大まかにはhereの例に基づいています。Plotly pythonバブルチャート - テキストを追加

これは私のコードです:次のように

bubbletext = dfenv[['Max_FZ','Argmax_FZ']] # dataframe with the 2 cols I need for text 
bubbletext = bubbletext.values.tolist() # puts the df into list of lists 

trace1 = Scatter(
     x=dfenv['X (ft)'], 
     y=dfenv['Y (ft)'], 
     text=bubbletext, # here's the problem 
     mode='markers', 
     marker=Marker(
      size=dfenv['Max_FZ'], 
      sizeref= dfenv['Max_FZ'].max()/1e2**2, 
      sizemode='area' 
      ) 
     ) 
data = Data([trace1]) 
layout = Layout(showlegend=False) 
fig = Figure(data=data)#, layout=layout) 
plot_url = py.plot(fig, filename='Envelope_MaxBubblechart') 

答えて

1

実際に、あなたは、ツールチップのテキストのための新しい文字列列を連結することができます

dfenv['text'] = dfenv['Max_FZ'].round(1).astype(str) + 'units' + '<br>at: ' + dfenv['Argmax_FZ'] 

trace1 = Scatter(
    x=dfenv['X (ft)'], 
    y=dfenv['Y (ft)'], 
    text=dfenv['text'], #string df column here with line breaks if needed 
    mode='markers', 
    marker=Marker(
     size=dfenv['Max_FZ'], 
     sizeref= dfenv['Max_FZ'].max()/1e2**2, 
     sizemode='area' 
     ) 
    ) 
data = Data([trace1]) 
fig = Figure(data=data) 
plot_url = py.plot(fig, filename='Envelope_MaxBubblechart') 
関連する問題