绘制python气泡图添加纹理

2024-04-26 01:06:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要用python将文本添加到绘制的气泡图中。我只能让text属性为每个数据点取1个值。但是,对于每个数据点,我需要在工具提示上显示两个值:其大小和另一个值。我使用的是一个列表列表,松散地基于一个示例here。在

这是我的代码:

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

Tags: the数据text列表datahereplotfig
1条回答
网友
1楼 · 发布于 2024-04-26 01:06:57

实际上,可以为工具提示的文本连接一个新的字符串列,如下所示:

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

相关问题 更多 >