Python画出好看的地图基于folium

[复制链接]
3 L+ {1 ]; H: W t' `2 F

Choropleth 等值线图

/ l8 A ^$ K+ G9 J& K# `
import pandas as pd #读取数据* q+ d& E$ j# }; M8 h from folium import Map,Choropleth,CircleMarker #用到的包 ! \ w. J7 U% `; p$ I9 J& T E& ]
8 ^6 ^. _$ Q0 Y; ]6 o9 E
#包含省的中国地图json : n8 O" e3 b4 l" ?" O5 \ china_geo = fhttps://geo.datav.aliyun.com/areas_v2/bound/100000_full.json7 L( u+ _7 k+ V7 T #读取用到的面积数据' N+ [, q4 d' l7 D+ } datad = pd.read_csv(Desktop/square.csv,index_col=index)9 J' U0 |* W! m2 i8 }! Z! j" Q& v1 f
& v7 k) G8 t+ m0 n+ F: y
% e+ c6 A% ? H/ z* t
m=Map(tiles=Stamen Toner) #地图风格7 m$ s1 \# ^1 l9 ~0 f$ t! P6 S: R ) E$ A8 ^; T8 P Choropleth(china_geo, #选择json ) C* k; l3 r. s: }9 ?9 j5 D data = datad, #数据 . O1 c* u J1 n# x% k columns = [province,square], #列,第一个为key,第二个为value 3 _0 F- u; A7 r D- n- Q+ ? key_on = feature.properties.name,#匹配到json: c u3 f" k) }! `" e5 s fill_color = RdPu, #颜色2 k) E& P7 Z7 ?7 p4 G7 Y fill_opacity = 0.8, #填充透明度; j2 b0 ^+ ~5 y( Z e: r1 a/ ? line_opactity = 1, #线透明度# h, }, v/ `! F, b! X. z0 m line_weight = 1, #线宽8 _5 S8 ^) j; z2 O8 _ legend_name = 面积 #图例 . \, {9 O. @) o 8 Z \! O% f) y/ o- ~8 z ).add_to(m) 8 \, [- \( ?+ c! ] CircleMarker(location = [39.907518, 116.397514], #坐标点 S8 {, R. r6 A& y+ P/ p4 { radius = 10, #半径( C" r0 m( n! \. h s1 i& { fill = True, #填充" X5 i# d% f% c5 s) D popup = This is beijing, #弹窗- C k R, Z6 j' } weight = 1 #circlemarker线宽 4 { d: o: }: i/ D ).add_to(m) ) c0 [, e! Y! f+ F6 C m.fit_bounds(m.get_bounds()) 1 I3 x Y6 v. L& n9 f m ( ~* H3 G0 ~! R+ H& {' g7 @7 _
9 F1 j% ^1 k) F" q+ @* t( Z0 ^- t
6 u8 {7 M2 t9 L, u. h; u

数据地址: square.rar - 蓝奏云

# V9 |& ]+ X: S7 E( P

两个重要的网站

2 X e' }* S' e ~

手动绘制geojson

5 U2 b% V. B$ {/ _! D7 N 6 b. ]" `3 Z% O K% k, l' m

目前更新的geojson

5 P4 [* O: ?) ]' R9 N 2 x! e* v6 R8 x+ a- B5 t

geojson格式

8 b; [2 q- q& f, ?0 _# c) n
{ 1 K: }9 ]8 N0 J3 S "type": "FeatureCollection",9 c6 ^/ _4 V2 L( S "features": [( A5 d1 a$ t/ ]/ X {: U; F: \( b* t7 i, A8 C6 w "properties": {"name": "Alabama"},) W' O: W% R) R. k9 a "id": "AL", , e# Y3 A3 T. i' i9 i& F' w "type": "Feature",2 G# B; p ~; F0 I# _ a" A# g4 H H "geometry": {+ d7 V' f) e9 ^4 O# }8 c8 c: s "type": "Polygon", % v9 i2 B D) g- j- M "coordinates": [[[-87.359296, 35.00118], ...]]- n l8 k4 c: D v3 S6 Y! _9 a }4 F7 t/ m' w1 s% A+ V. Z$ } },) X3 N: L! o- ] e& Y u! K { * J9 M" q+ v$ W q "properties": {"name": "Alaska"}, " J7 H5 G- A3 _( B8 N/ r "id": "AK",1 R% k D7 G# U* ^7 |1 h. ^ "type": "Feature",; T9 u! @) [# U2 j' e$ z t. a "geometry": {( F6 q5 b8 @" C, X "type": "MultiPolygon",5 h1 f9 P' J2 j0 A "coordinates": [[[[-131.602021, 55.117982], ... ]]] 4 p% |1 Y$ ]3 ~3 e2 V- K# j; f# g }3 P# B) f' e$ h* t. R/ d }, . T* A3 }: J5 o$ y5 d ...) e8 `9 G8 O7 p( m3 A4 p ] ' U; J2 Z+ {3 U# L* C }3 P6 F# Q4 a6 P! I: G( @
% B; }2 H8 \$ R2 g

读取本地的json文件

# z) h0 |9 C) O! R
f = open(zhengzhou.json) 8 W* o) Y. f% k% f- j t = json.load(f)1 r6 ~1 ^8 c6 r7 x" L1 T; x
- A/ w8 {9 K) o# d

读取网络json

; V; [! m( {( p4 A1 P7 s7 t
url = (+ ^# ]3 `3 d6 u7 A# ~. { h "https://raw.githubusercontent.com/python-visualization/folium/master/examples/data" / o7 }1 _) f6 d* B ) {& r" G1 u: ?: S- M us_states = f"{url}/us-states.json" }" d& r' i' z8 I5 t; K8 ~ 4 u+ p" t" w; K geo_json_data = json.loads(requests.get(us_states).text)9 c5 d7 I a1 @2 x/ k
. r8 H' ~) U. W& D " r I1 R5 {6 u( O9 W/ `1 p " \- s& S3 n1 w7 ? 5 C6 \9 O! x8 w$ C 0 r+ f7 d: E3 g, e8 n, R4 h
回复

举报 使用道具

相关帖子

全部回帖
暂无回帖,快来参与回复吧
懒得打字?点击右侧快捷回复 【吾爱海洋论坛发文有奖】
您需要登录后才可以回帖 登录 | 立即注册
华德地毯
活跃在2024-12-1
快速回复 返回顶部 返回列表