只摸索出全部省份的地圖,直接設定引數即可,做出來的圖挺好看,所以記錄一下,
選擇部分省份作圖或對某一個具體地區作圖,特別是用于論文、研究等,需要圖片十分清晰,還是專業地圖繪制軟體更合適,
1. 創建備用資料
import pandas as pd
geo_test_data=[('北京',100),('上海',90),
('江蘇',88),('陜西',78),
('河北',10),('湖南',66)]
df=pd.DataFrame(geo_test_data)
df.columns=['province','number']
df

2. Geo做散點圖
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType,SymbolType
%matplotlib inline
geo=Geo()
geo.add_schema(maptype='china') #選定地圖范圍
geo.add('geo',geo_test_data, #地圖資料(串列資料)
type_=ChartType.EFFECT_SCATTER,
#'heatmap':熱力圖 ChartType.EFFECT_SCATTER:動態散點圖
symbol_size=15)
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) #是否顯示資料標簽
geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=False), #是否顯示圖例
#is_piecewise:圖例是否分段
title_opts=opts.TitleOpts(title='Geo-基本示例')) #圖形標題
geo.render('geo.html') #保存為網頁資料
geo.render_notebook() #在notebook中顯示

3. map做散點圖
3.1 散點圖
from pyecharts import options as opts
from pyecharts.charts import Map
map=Map()
map.add('頻數',geo_test_data,'china')
map.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) #是否顯示label(省份名),需要單獨的命令設定
map.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
map.render_notebook()

3.2 著色圖
map=Map()
map.add('頻數',geo_test_data,'china')
map.set_global_opts(
title_opts=opts.TitleOpts(title='示例'),
visualmap_opts=opts.VisualMapOpts(max_=200,
is_piecewise=True)) #圖例是否分段
map.render_notebook()

pyecharts在jupyter notebook中做出來的圖,可以直接顯示,也可以保存成html檔案,分享給別人鏈接,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/282883.html
標籤:其他
上一篇:C語言編程規范(個人整理)
