我有一个与美国每个州相关的值(假设它是每个州一月份的平均温度)。我想将此数据显示为美国的热图。需要明确的是,这将是一张美国地图,每个州的颜色都来自与定量值相对应的颜色梯度。我不知道这种绘图类型叫什么,所以我无法弄清楚如何在 MATLAB 或其他程序中执行此操作,但有人知道一种简单的方法吗?我有一个数据向量(长度为 50),只需要制作一个美国地图。
如何创建美国州等值线地图
数据挖掘
数据
2021-09-26 03:11:14
3个回答
Python 中的 Plotly提供了一个很好的解决方案:
!pip install chart_studio
from chart_studio import 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 )
url = py.plot( fig, filename='d3-cloropleth-map' )
R,带有googlevis 包,也提供了很好的解决方案(交互式 html 地图):
require(datasets)
states <- data.frame(state.name, state.x77)
GeoStates <- gvisGeoChart(states, "state.name", "Illiteracy",
options=list(region="US",
displayMode="regions",
resolution="provinces",
width=600, height=400))
plot(GeoStates)
其它你可能感兴趣的问题