python -- pyecharts library geo function / map function to realize the visualization of map data

Guide Kit:

In order to mention the speed of the guide packet, the pip is performed through Tsinghua image

Import pyecharts package

(pyecharts version 0.5.10 is selected here)

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts==0.5.10

Import map package

The map data files are as follows:
Global country map: echarts countries pypkg
China provinces pypkg
City map of China: echarts China cities pypkg
Others: echarts China counts pypkg
echarts-china-misc-pypkg

How to customize (add / modify) latitude and longitude coordinates in Geo/Map?
Related documents:
Custom data: https://github.com/pyecharts/geo-region-coords

The Geo coordinate system component is used for map drawing, and supports the drawing of scatter map and line set on the Geo coordinate system.
Map function map is mainly used for visualization of geographic area data.

pip install -i https://pypi.doubanio.com/simple/ echarts-countries-pypkg
pip install -i https://pypi.doubanio.com/simple/ echarts-china-provinces-pypkg
pip install -i https://pypi.doubanio.com/simple/ echarts-china-cities-pypkg
pip install -i https://pypi.doubanio.com/simple/ echarts-china-counties-pypkg
pip install -i https://pypi.doubanio.com/simple/ echarts-china-misc-pypkg

geo function

Basic grammar

geo.add(name, #legend title
	attr, value, #Property name, the value corresponding to the property
	type="scatter", #Legend types include 'scatter', 'effectscatter', and 'Heatmap'. Default is' scatter '
	maptype='china', #Map type
	coordinate_region='China', #City coordinate country
	symbol_size=12, #Tag drawing size. The default is 12.
	border_color="#111", #Map border color. Default is'#111'
	geo_normal_color="#323c48",#The color of the map area in normal state. Default is'#323c48'
	geo_emphasis_color="#2a333d", #The color of the map area in the highlighted state. Default is'#2a333d'
	geo_cities_coords=None, #User defined regional longitude and latitude dictionary, similar to {'Wuwei City': [117.902366,31.303168],}
	is_roam=True, #Whether to turn on mouse zoom and pan roaming. 'scale' zoom, 'move' pan, 'True' are all on; the default is True.
	**kwargs)

Preparation data

Set map parameters

import pandas as pd
from pyecharts import Geo

df=pd.read_excel('C:/Users/Administrator/Desktop/Summary of epidemic data in Anhui Province/Risklevel.xlsx',
                 sheet_name='Sheet3',
                 names=['Areacity','Areacountry','RISK','LEVEL'])

#print(df) can check whether the data is imported correctly
area = df['Areacountry']
value =df['RISK']

geo = Geo(
        "Risk level of novel coronavirus pneumonia in Anhui", #Headline
        "(As of 24:00 on February 23, 2020)",#Subheading
        title_color="#fff",#Title Color
        title_text_size=24, #Title Size
        title_top=25, #Distance between title and top
        title_pos="center",#Title Location
        width=400, height=600, #Drawing area size
        background_color='#404a59' #background color
        )

#Manually supplement the latitude and longitude coordinates of the missing area
geo.add_coordinate('Jieshou',118.27309,32.085407)
geo.add_coordinate('Wuwei City',117.902366,31.303168)

Thermodynamic chart

geo.add("Risk level of novel coronavirus pneumonia in Anhui", # Family name, used for the display of toolip, legend filtering of legend.
        area, value,# Data item (coordinate point name, coordinate point value)
        maptype = 'Anhui',  #str, map type, specific reference 
        type='heatmap',# Geo map type
        #There are four kinds of scatter, effectscatter, Heatmap and lines. It is recommended to use
        # from pyecharts.globals import GeoType
        # GeoType.GeoType.EFFECT_SCATTER,GeoType.HEATMAP,GeoType.LINES
        visual_range=[1,3],
        symbol_size=25,
        is_roam = True,#bool, whether to turn on mouse zoom and pan roaming
        label_opts= None,# Label configuration item, for example: [opts.LabelOpts, dict, None] 
        is_visualmap=True,
        #is_piecewise=True,#Sectional legend
        visual_text_color='#fff',  #Text color of color bar
        is_label_show=True
        )
 
geo.render('C:/Users/Administrator/Desktop/Summary of epidemic data in Anhui Province/Risk level of novel coronavirus pneumonia in Anhui.html')

Score chart (scatter with ripples)

geo.add("Risk level of novel coronavirus pneumonia in Anhui", # Family name, used for the display of toolip, legend filtering of legend.
        area, value,# Data item (coordinate point name, coordinate point value)
        maptype = 'Anhui',  #str, map type, specific reference 
        type='effectScatter',# Geo map type
        symbol_size=5,#Scatter size
		effect_scale=5, #The size of the ripples
        visual_range=[1,3],
        is_roam = True,#bool, whether to turn on mouse zoom and pan roaming
        label_opts= None,# Label configuration item
        is_visualmap=True,
        #is_piecewise=True,#Color bar segments
        visual_text_color='#fff',  #Text color of color bar
        is_label_show=False  #Display label
        )
 
geo.render('C:/Users/Administrator/Desktop/Summary of epidemic data in Anhui Province/Risk level of novel coronavirus pneumonia in Anhui.html')


Color bar segments

map function

import pandas as pd
from pyecharts import Map

# Provinces and municipalities
province_distribution = {'Henan': 45.23, 'Beijing': 37.56, 'Hebei': 21, 'Liaoning': 12, 'Jiangxi': 6, 'Shanghai': 20, 'Anhui': 10, 'Jiangsu': 16, 'Hunan': 9, 'Zhejiang': 13, 'Hainan': 2, 'Guangdong': 22, 'Hubei': 8, 'Heilongjiang': 11, 'Macao': 1, 'Shaanxi': 11, 'Sichuan': 7, 'Inner Mongolia': 3, 'Chongqing': 3, 'Yunnan': 6, 'Guizhou': 2, 'Jilin': 3, 'Shanxi': 12, 'Shandong': 11, 'Fujian': 4, 'Qinghai': 1, 'Helmsman technology, quality assurance': 1, 'Tianjin': 1, 'Other': 1}
provice=list(province_distribution.keys())
values=list(province_distribution.values())

map = Map(
        "Map practice of China", #Headline
        "(2020 24:00, February 24, 2004)",#Subheading
        title_color="#fff",#Title Color
        title_text_size=24, #Title Size
        title_top=25, #Distance between title and top
        title_pos="center",#Title Location
        width=800, height=600, #Drawing area size
        background_color='#404a59' #background color
        )
                
map.add("map of China", # Family name, used for the display of toolip, legend filtering of legend.
        provice, values,# Data item (coordinate point name, coordinate point value)
        maptype = 'china',  #Show only municipalities and provinces directly under the central government
        type="effectScatter",
        is_random=True,
        visual_range=[0,50],
        is_visualmap=True,
        geo_emphasis_color='#F5D0A9',
        visual_text_color='#fff',  #Text color of color bar
        is_label_show=False  #Display label
        )
 
map.render('C:/Users/Administrator/Desktop/map function.html')

Reference materials:
Notes on the use of Map and Geo in Pyecharts

Published 10 original articles, won praise 4, visited 563
Private letter follow

Tags: pip github

Posted on Mon, 24 Feb 2020 07:19:45 -0800 by dmort