6 N' l4 @2 ^( C4 i. q. T3 {3 E" j Choropleth 等值线图
( o! @+ A8 I9 T: o' J* c1 W import pandas as pd #读取数据
j% l, f8 g2 d! q from folium import Map,Choropleth,CircleMarker #用到的包2 o1 K6 z7 d2 `: f. H
, `3 i( @- m/ Y #包含省的中国地图json
' x h( ^0 E2 l& ]0 f) x6 q+ g china_geo = fhttps://geo.datav.aliyun.com/areas_v2/bound/100000_full.json- {3 ?4 V+ W6 n6 E2 ]6 Q( p* I
#读取用到的面积数据' J7 k7 |: v* J9 B) J9 U
datad = pd.read_csv(Desktop/square.csv,index_col=index)
0 D4 o S c( T7 [# f" y8 ?, G; I
( D8 ?: o* M6 U- _4 J- q
/ h& b q- B5 K9 h" Q+ N# S# V m=Map(tiles=Stamen Toner) #地图风格( ^- ~) w u0 m6 v7 @6 H- B* q
- J& K `) _5 w3 R4 C6 F Choropleth(china_geo, #选择json
+ B' C, c) d" G; ^; k, v data = datad, #数据
0 P# K% Q" j+ l! b/ ^ columns = [province,square], #列,第一个为key,第二个为value' l* s- |$ Q0 l _0 A
key_on = feature.properties.name,#匹配到json
% H; Q0 B/ Q& @# o1 V fill_color = RdPu, #颜色+ E4 }! q- ]4 ^4 O. _( L
fill_opacity = 0.8, #填充透明度- J7 _+ B2 d6 T+ {. Q: p
line_opactity = 1, #线透明度
; R0 t4 w6 e9 [8 Q) n line_weight = 1, #线宽" i2 q O3 H! ?( q
legend_name = 面积 #图例
. t* \! B5 s* d% r- ?& f' M" O' L
9 L4 n0 S1 V& @+ e* M$ _0 T ).add_to(m)
" k) |% P' I; H. K CircleMarker(location = [39.907518, 116.397514], #坐标点
" |5 U' M$ V/ L7 @ M2 Y- o" d6 C radius = 10, #半径
3 G9 `$ x9 M' j fill = True, #填充
2 n: e) g/ h! v; `( @8 t) V popup = This is beijing, #弹窗
) k+ Y2 j- y3 S N weight = 1 #circlemarker线宽
$ S' x# a/ S6 ]: C6 _ ).add_to(m)/ b+ @. c/ L, [ W' q
m.fit_bounds(m.get_bounds())
8 \ F- r J% e q7 E* j6 X m0 Z, ` i) R! X+ `7 l" C0 g% ~
! }) L: g3 U+ v: o6 k9 A
% E5 ?* E& I* t6 {0 S1 w( w 数据地址: square.rar - 蓝奏云
; U% V; e9 H9 ^# [ z# `1 J 两个重要的网站
: p3 e0 L; Z3 j. k6 Q( y 手动绘制geojson 0 g8 L% o) g9 e l# M$ ~- a: d
S _4 t+ l& @, h
目前更新的geojson 6 Y* g/ f+ x, t9 Y' x
; g! b+ s$ \4 \% b2 G; q( Q
geojson格式 ! B9 s# B9 p$ c. U) Q
{' p+ Y7 ]6 a( k* k _% R% x
"type": "FeatureCollection",
) w/ C4 W- B4 A" b3 Z6 F3 B "features": [
3 T3 z7 C$ V, L {4 P2 y3 w7 X/ ?- b3 t% o
"properties": {"name": "Alabama"},- Y- b! |# n/ H3 k% G$ v
"id": "AL",
4 n e3 p6 d3 u/ c9 d "type": "Feature",
* i- Q# Y9 Z- ~% \$ U "geometry": {/ y# U2 e+ h% _. F1 p; s
"type": "Polygon",
4 a5 \; y- u3 w "coordinates": [[[-87.359296, 35.00118], ...]]
/ I2 t9 L3 B! _- G }
6 c: {' q" h, X9 H8 z: ^ },
3 z# D8 t0 X1 I& }) K3 W {
# [7 ^6 j4 N, Z% T0 D "properties": {"name": "Alaska"},
6 F' l& p$ N6 Y "id": "AK",& L3 |1 [% A3 c; h5 D* }( |' Y
"type": "Feature",4 ]) g% y. u( U+ W: Z' u
"geometry": {
4 t5 I' T" ]8 q8 B, i3 ?) t "type": "MultiPolygon",9 g# H9 N: e" o# w
"coordinates": [[[[-131.602021, 55.117982], ... ]]]
) Q0 P; H! ]$ u' ^% z: g* ` }
2 m6 L n$ K- r$ W* p" e8 _ },
" C. x0 _# k$ P. x2 s7 W9 x. ? ..." Q, ~9 Z3 I" [+ s/ H' Q1 N. n6 b
]
, | ~& c6 [& x$ `9 i }. L4 j/ |! d! M1 u# V: C
' q1 | z) J3 [" Z 读取本地的json文件
& X( Z' J' V5 u) \, c f = open(zhengzhou.json)
8 c7 b" u, |; U1 q" H# } t = json.load(f)" p. B' X Q0 u2 A0 K. D
/ \. z, \. {! |, o* S e
读取网络json ( ^2 v: t6 J- ]6 r3 {2 C* M1 |
url = (
/ w ] c8 ^0 T2 L. Z9 E) \' l% k* e0 W "https://raw.githubusercontent.com/python-visualization/folium/master/examples/data"
# ^- s, _6 f V )6 \7 R+ `- Y3 n: F& F
us_states = f"{url}/us-states.json"7 _% a S7 N7 l% Y9 i
. y3 c) h; x. F% g
geo_json_data = json.loads(requests.get(us_states).text)) x$ z ^4 ^8 h, E( A
+ V# U/ N% N ^, Y( p& Z' L" o) l7 T* O' Q; c
4 r9 e8 B0 [& {$ M" ~
" z: p/ w. L" X o7 @
( k2 j: a: a' X b. v |