簡體   English   中英

更改懸停在等值線圖上的等值線圖時出現的內容的屬性

[英]Changing the attributes of the what appears when hovering over a Choropleth Map in plotly

我在Python 3.6.3中使用plotly ,我正在嘗試像這里一樣做一個Choropleth地圖。 我想改變懸停在地圖上方時出現的屬性。 也就是說,例如,如果我們考慮加利福尼亞的第一張地圖和懸停,它看起來像:

在此輸入圖像描述

我想更改顯示的內容的字體大小和框的大小。 有沒有辦法訪問這些?

以下是生成它的代碼:

import plotly.plotly as py
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')

for col in df.columns:
    df[col] = df[col].astype(str)

scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\
            [0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]

df['text'] = df['state'] + '<br>' +\
    'Beef '+df['beef']+' Dairy '+df['dairy']+'<br>'+\
    'Fruits '+df['total fruits']+' Veggies ' + df['total veggies']+'<br>'+\
    'Wheat '+df['wheat']+' Corn '+df['corn']

data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df['code'],
        z = df['total exports'].astype(float),
        locationmode = 'USA-states',
        text = df['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "Millions USD")
        ) ]

layout = dict(
        title = '2011 US Agriculture Exports by State<br>(Hover for breakdown)',
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)'),
             )

fig = dict( data=data, layout=layout )
py.iplot( fig, filename='d3-cloropleth-map' )

chloropleth> hoverlabel函數允許您設置背景顏色,邊框顏色和字體。 但是,邊框的大小由其中的文本確定。 如果名稱顯示為截斷,則可以使用chloropleth> hoverlabel> namelength函數進行擴展。

暫無
暫無

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

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