1

I need to add text to a plotly bubble chart with python. I can only get the text attribute to take 1 value per datapoint. However, for each datapoint I need to show two values on the tooltip: its size, and another value. I'm using a list of lists, loosely based on an example here.

This is my code:

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 Answer 1

1

Actually, you can concatenate a new string column for the text of the tooltip as follows:

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.