Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of drawing Map of China by Python pyecharts

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly analyzes the relevant knowledge points of the case analysis of Python pyecharts to realize the mapping of China, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor to have a look, and follow the editor to learn the knowledge of "Python pyecharts to realize the case analysis of mapping China".

Example demonstration

First of all, let's show you the effect map.

Installation and data preparation of 1.pyecharts version 1.9.1

First of all, you need to install the pyecharts library, just pip install pyecharts it.

The new version does not need to install the map separately. If it is version 0.5, it needs to be installed separately. The current demonstration is the latest version 1.9.1.

The map data is as follows:

Because it is a map of China, so for the target province, I set up two groups, in which the data is randomly generated.

#-*-coding:utf-8-*-# 2022-1-1 "author: Xiaolanzao # pyecharts Map # need to refer to the library from pyecharts import options as optsfrom pyecharts.charts import Mapimport random# to set up the relevant provinces where Altman exists And set the initial quantity as 0ultraman = [['Sichuan', 0], ['Taiwan', 0], ['Xinjiang', 0], ['Jiangxi', 0], ['Henan', 0], ['Liaoning', 0], ['Xizang', 0]] # set the relevant provinces where the monster exists And set the initial quantity as 0monster = ['Guangdong', 0], ['Beijing', 0], ['Shanghai', 0], ['Jiangxi', 0], ['Hunan', 0], ['Zhejiang', 0], ['Jiangsu' 0]] def data_filling (array):''function: fill array data with random numbers' for i in array: # randomly generate random numbers from 1 to 1000 [1] = random.randint (1) print (I) data_filling (ultraman) data_filling (monster) 2. Add data items, default China map display

First of all, the demo will add a set of data, and after running it, you will generate a html file, and after opening it, you can view the generated map.

Def create_china_map ():''function: to generate a map of China (Map () .add (series_name= "monster", data_pair=monster, maptype= "china") ) # set title .set _ global_opts (title_opts=opts.TitleOpts (title= "Map of China")) # generate local html file .render ("Map of China .html"))

Then add two sets of data to the demo, just add an add () function, which is very convenient.

Def create_china_map ():''function: to generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china",) .add (series_name= "monster", data_pair=monster, maptype= "china") ) # set title .set _ global_opts (title_opts=opts.TitleOpts (title= "Map of China")) # generate local html file .render ("Map of China .html"))

Common configuration items and parameter analysis 1. Sets whether it is selected by default

The default is selected, and the is_selected=False parameter can be added to set not to display by default.

Def create_china_map ():''function: to generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china") # whether to select is_selected=False by default) .add (series_name= "monster", data_pair=monster, maptype= "china" ) # set the title .set _ global_opts (title_opts=opts.TitleOpts (title= "Map of China")) # generate a local html file. Render ("Map of China .html") create_china_map ()

You can see that only the monster's data are displayed by default.

two。 Sets whether the map color type is displayed in segments

The visual mapping configuration item visualmap_opts=opts.VisualMapOpts (max_=1000, is_piecewise=True) can be set to display in segments of the map color type, the value of max_ corresponds to the range of data, and the parameter is_piecewise=True is expressed as segmented display.

Def create_china_map ():''function: to generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china") # whether to select is_selected=True by default) .add (series_name= "monster", data_pair=monster, maptype= "china",) .set _ global_opts (# set title title_opts=opts.TitleOpts (title= "map of China") # set segmented display visualmap_opts=opts.VisualMapOpts (max_=1000, is_piecewise=True)) # generate local html file .render ("map of China .html"))

Display the effect picture in segments:

Def create_china_map ():''function: to generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china") # whether to select is_selected=True by default) .add (series_name= "monster", data_pair=monster, maptype= "china",) .set _ global_opts (# set title title_opts=opts.TitleOpts (title= "map of China") # set standard display visualmap_opts=opts.VisualMapOpts (max_=1000, is_piecewise=False)) # generate local html file .render ("map of China .html"))

This is the standard display with a parameter of is_piecewise=False.

3. Zoom Pan configuration

The parameter is_roam=False controls that mouse zooming and panning are not possible.

Def create_china_map ():''function: generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china", whether # is selected by default) Default is True is_selected=True, whether # enables mouse wheel zooming and dragging panning Default is True is_roam=False) .add (series_name= "monster", data_pair=monster, maptype= "china",) .set _ global_opts (# set title title_opts=opts.TitleOpts (title= "map of China"), # set standard display visualmap_opts=opts.VisualMapOpts (max_=1000 Is_piecewise=False)) # generate local html file .render ("map of China .html"))

The mouse wheel can zoom in and out of the image when the parameter is enabled.

The mouse can drag left and right to pan the map.

Priority statement: a data set to False,b data set to True, do not select a data, you can also zoom and pan drag.

4. Turn drawing markup on and off

The parameter is_map_symbol_show=False can turn off the drawing tag, and the point will not be displayed when it is turned off.

Def create_china_map ():''function: generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china", whether # is selected by default) Default is True is_selected=True, whether # enables mouse wheel zooming and drag panning, default is True is_roam=True, and # whether graphic markers are displayed Default is True is_map_symbol_show=False) .add (series_name= "monster", data_pair=monster, maptype= "china",) .set _ global_opts (# set title title_opts=opts.TitleOpts (title= "map of China") # set standard display visualmap_opts=opts.VisualMapOpts (max_=1000, is_piecewise=False)) # generate local html file .render ("map of China .html"))

You can see that the points in the Altman-related area are gone.

5. Turn off the display of label names

The parameter label_opts=opts.LabelOpts (is_show=False) of the series configuration item turns off the display of the label name.

Def create_china_map ():''function: generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china", whether # is selected by default) Default is True is_selected=True, whether # enables mouse wheel zooming and drag panning, default is True is_roam=True, and # whether graphic markers are displayed Default is True is_map_symbol_show=False) .add (series_name= "monster", data_pair=monster, maptype= "china",) # global configuration item.set _ global_opts (# set title title_opts=opts.TitleOpts (title= "map of China") # set standard display visualmap_opts=opts.VisualMapOpts (max_=1000, is_piecewise=False),) # Series configuration items # turn off tag name display .set _ series_opts (label_opts=opts.LabelOpts (is_show=False)) # generate local html file .render ("Map of China .html"))

You can see that the name of the province is no longer displayed.

6. Color settings: label color, area color, border color

The label in the series configuration item plus the color= "bule" parameter sets the label color to blue.

AreaColor configured for element style is area color, and borderColor is border color

The normal is in the normal mode and the emphasis is in the emphasis style, that is, the display by moving the mouse over the area.

# element style configuration itemstyle_opts= {# regular display "normal": {"areaColor": "white", "borderColor": "red"}, # emphasis color "emphasis": {"areaColor": "rgba"

You can see that my mouse moves to Xinjiang to display the black set for me, and the transparency is 1.

Def create_china_map ():''function: generate a map of China (Map () .add (series_name= "Altman", data_pair=ultraman, maptype= "china", whether # is selected by default) Default is True is_selected=True, whether # enables mouse wheel zooming and drag panning, default is True is_roam=True, and # whether graphic markers are displayed The default is True is_map_symbol_show=False, # element style configuration itemstyle_opts= {# regular display "normal": {"areaColor": "white", "borderColor": "red"}, # accent color "emphasis": {"areaColor": "rgba (0P0) 0jue 1) "}}) .add (series_name=" monster ", data_pair=monster, maptype=" china ",) # global configuration item.set _ global_opts (# set title title_opts=opts.TitleOpts (title=" Map of China ") # set standard display visualmap_opts=opts.VisualMapOpts (max_=1000, is_piecewise=False)) # Series configuration items .set _ series_opts (# label name display The default is True label_opts=opts.LabelOpts (is_show=True, color= "blue") # generate local html files. Render ("Map of China. Html") what are the common libraries of python python commonly used libraries: 1.requesuts 2.scrapyters3.pillowblows4.twistedters5.numpyters6.matplotlibter7.pygamatransfer8.ipyhton, etc.

On the "Python pyecharts implementation of the case analysis of mapping China" is introduced here, more relevant content can be searched for previous articles, hope to help you answer questions, please support the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report