第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有聚合的繪圖地理散布:在懸停中顯示聚合信息

帶有聚合的繪圖地理散布:在懸停中顯示聚合信息

梵蒂岡之花 2021-05-15 14:15:50
我一直在嘗試用Plotly創(chuàng)建Geoscatter Plot,其中標(biāo)記大小應(yīng)指示一個城市(zip_city)中的客戶(行項目)數(shù)量。我的代碼基于Plotly文檔中的兩個模板:United States Bubble Map和Aggregation part with Aggregates映射。除了一個缺點,我設(shè)法編寫了符合我想要的代碼:當(dāng)我將鼠標(biāo)懸停在氣泡上時,我想查看城市名稱加上客戶數(shù)量(匯總結(jié)果),因此阿瓜迪亞:2。您能幫我怎么做嗎?這是我的代碼(作為plotly的初學(xué)者,我也愿意進行代碼改進):import plotly.offline as pyoimport pandas as pddf = pd.DataFrame.from_dict({'Customer': [111, 222, 555, 666],        'zip_city': ['Aguadilla', 'Aguadilla', 'Arecibo', 'Wrangell'],        'zip_latitude':[18.498987, 18.498987, 18.449732,56.409507],        'zip_longitude':[-67.13699,-67.13699,-66.69879,-132.33822]})data = [dict(        type = 'scattergeo',        locationmode = 'USA-states',        lon = df['zip_longitude'],        lat = df['zip_latitude'],        text = df['Customer'],        marker = dict(            size = df['Customer'],            line = dict(width=0.5, color='rgb(40,40,40)'),            sizemode = 'area'            ),        transforms = [dict(                            type = 'aggregate',                            groups = df['zip_city'],                            aggregations = [dict(target = df['Customer'], func = 'count', enabled = True)]                            )]        )]layout = dict(title = 'Customers per US City')fig = dict( data=data, layout=layout )pyo.plot( fig, validate=False)我可以transforms直接在data參數(shù)中訪問參數(shù)結(jié)果以顯示每個城市的客戶數(shù)量嗎?
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經(jīng)驗 獲得超9個贊

您可以創(chuàng)建一個列表,其中將包含您想要的內(nèi)容,然后text=list在中進行設(shè)置data。也不要忘記指定hoverinfo='text'。


我已經(jīng)更新了您的代碼,因此請嘗試以下操作:


import pandas as pd

import plotly.offline as pyo


df = pd.DataFrame.from_dict({'Customer': [111, 222, 555, 666],

        'zip_city': ['Aguadilla', 'Aguadilla', 'Arecibo', 'Wrangell'],

        'zip_latitude':[18.498987, 18.498987, 18.449732,56.409507],

        'zip_longitude':[-67.13699,-67.13699,-66.69879,-132.33822]})


customer = df['Customer'].tolist()

zipcity = df['zip_city'].tolist()

list = []

for i in range(len(customer)):

    k = str(zipcity[i]) + ':' + str(customer[i])

    list.append(k)


data = [dict(

        type = 'scattergeo',

        locationmode = 'USA-states',

        lon = df['zip_longitude'],

        lat = df['zip_latitude'],

        text = list,

        hoverinfo = 'text',

        marker = dict(

            size = df['Customer'],

            line = dict(width=0.5, color='rgb(40,40,40)'),

            sizemode = 'area'

            ),

        transforms = [dict(

                            type = 'aggregate',

                            groups = df['zip_city'],

                            aggregations = [dict(target = df['Customer'], func = 'count', enabled = True)]

                            )]

        )]


layout = dict(title = 'Customers per US City')


fig = dict(data=data, layout=layout)

pyo.plot(fig, validate=False)  


查看完整回答
反對 回復(fù) 2021-05-18
  • 1 回答
  • 0 關(guān)注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號