簡體   English   中英

Plotly hoverinfo顯示所有數據點而不是當前點

[英]Plotly hoverinfo shows all data points instead of current point

我無法獲得plotly的hoverinfo屬性來顯示給定點的單個值。 作為參考,我在地圖上繪制了一堆點,並希望能夠將鼠標懸停在一個點上並查看其唯一標識符。 如果我沒有為hoverinfotext設置任何值,我會在懸停時看到單個點的lat和lon值。 但是,當我設置text=nodes.Nodehoverinfo="text"我會在懸停在任何點上時看到所有節點的列表。 下面的代碼生成一個最小的例子(在jupyter筆記本中):

import pandas as pd
import plotly.offline as py
from plotly.graph_objs import *
py.init_notebook_mode()

nodes = pd.DataFrame({
    'Node': [103,131,136,143,153],
    'Lat': [39.97703048,39.98315706,40.02686848,40.02110808,40.01174032],
    'Lon': [-83.00179533,-82.97803884,-82.97319305,-83.01509991,-82.97285888]
})
mapbox_access_token = some_mapbox_token
data = Data([
    Scattermapbox(
        lat=nodes.Lat,
        lon=nodes.Lon,
        mode='markers',
        marker=Marker(
            size=2,
            color='red',
            opacity=0.7
        ),
        text=nodes.Node,
        hoverinfo='text'
    )]
)
layout = Layout(
    title='Nodes interacting with busiest TAZ',
    autosize=True,
    hovermode='Closest',
    showlegend=False,
    mapbox=dict(
        accesstoken=mapbox_access_token,
        bearing=0,
        center=dict(
            lat=39.983333,
            lon=-82.983333
        ),
        pitch=0,
        zoom=7.5
    ),
)

我的text設置不正確嗎? 或者它與hoverinfohovermode

看起來像是一個錯誤或未指定的行為給我。 你的代碼看起來很好,你只需要傳遞一個字符串列表而不是整數,它應該工作。

    text=[str(n) for n in nodes.Node]

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM