pyecharts V1.x uses Map to Map epidemic situation

pyecharts V1.x uses Map to Map epidemic situation

Pyecharts is a class library used to generate Echarts diagrams. The visualization of diagrams generated by Echarts is very good. Compared with the use of gis desktop product mapping, the use of pyecharts to make maps, less vector data restrictions, as long as the input of the correct format of data, you can quickly make maps, there are multiple sets of map styles can be used, for the production of some relatively simple, frequently changing charts has great advantages. Without much nonsense, start the code above.

    1. Epidemic situation map of China based on data of dingxiangyuan - fengis-2020 / 02 / 10
  • Implementation code
# -*- coding: utf-8 -*-

"""
@Author  : fungis@163.com
@Time    : 2020/2/9 13:12
"""

# Version V1 starts to support chain call
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.globals import ThemeType  # theme

# Provincial capital and municipality directly under the central government
data = [['Jiangsu', 492], ['Anhui', 830], ['Hunan', 879], ['Henan', 1073], ['Zhejiang', 1092], ['Guangdong', 1151], ['Tianjin', 94], ['Inner Mongolia', 58],
        ['Beijing', 337], ['Shaanxi', 213], ['Guangxi', 210], ['Ningxia', 49], ['Guizhou', 109], ['Shanghai', 295], ['Jiangxi', 771], ['Fujian', 261],
        ['Xinjiang', 49], ['Sichuan', 405], ['Yunnan', 141], ['Hainan', 136], ['Shandong', 459], ['Jilin', 80], ['Heilongjiang', 331], ['Hebei', 218],
        ['Hong Kong', 36], ['Chongqing', 468], ['Shanxi', 119], ['Gansu', 83], ['Hubei', 29631], ['Liaoning', 107], ['Taiwan', 18], ['Macao', 10],
        ['Qinghai', 18], ['Tibet', 1]]

# Method 1 set map parameters
map = (
    Map(init_opts=opts.InitOpts(bg_color="#FFFAFA", theme=ThemeType.ESSOS, width=1000))
        .add("Confirmed number", data)
        .set_global_opts(
        title_opts=opts.TitleOpts(title="fungis-Epidemic map based on the data of dingxiangyuan"),
        visualmap_opts=opts.VisualMapOpts(
            is_piecewise=True,  # Set whether to display in segments
            # Customize the range of each paragraph, as well as the text of each paragraph, and the special style of each paragraph. For example:
            pieces=[
                {"min": 2000, "label": '>2000 people', "color": "#eb2f06"},
                {"min": 1000, "max": 2000, "label": '1001-2000 people', "color": "#FF3030"},  # If max is not specified, it means that max is infinite.
                {"min": 500, "max": 1000, "label": '500-1000 people', "color": "#FF4500"},
                {"min": 100, "max": 499, "label": '100-499 people', "color": "#FF7F50"},
                {"min": 10, "max": 99, "label": '10-99 people', "color": "#FFA500"},
                {"min": 1, "max": 9, "label": '1-9 people', "color": "#FFDEAD"},
            ],
            # Text at both ends, such as ['high ',' low '].
            range_text=['high', 'low'],
        ),
    )
)
map.render(path="./Color map of China's epidemic population classification 1.html")
    1. Epidemic situation map of China based on data of dingxiangyuan - fengis-2020 / 02 / 10
  • Implementation code
# -*- coding: utf-8 -*-

"""
@Author  : fungis@163.com
@Time    : 2020/2/9 13:12
"""

from pyecharts import options as opts
from pyecharts.globals import ThemeType
from pyecharts.charts import Map#theme

# Provincial capital and municipality directly under the central government
data = [['Jiangsu', 492], ['Anhui', 830], ['Hunan', 879], ['Henan', 1073], ['Zhejiang', 1092], ['Guangdong', 1151], ['Tianjin', 94], ['Inner Mongolia', 58],
        ['Beijing', 337], ['Shaanxi', 213], ['Guangxi', 210], ['Ningxia', 49], ['Guizhou', 109], ['Shanghai', 295], ['Jiangxi', 771], ['Fujian', 261],
        ['Xinjiang', 49], ['Sichuan', 405], ['Yunnan', 141], ['Hainan', 136], ['Shandong', 459], ['Jilin', 80], ['Heilongjiang', 331], ['Hebei', 218],
        ['Hong Kong', 36], ['Chongqing', 468], ['Shanxi', 119], ['Gansu', 83], ['Hubei', 29631], ['Liaoning', 107], ['Taiwan', 18], ['Macao', 10],
        ['Qinghai', 18], ['Tibet', 1]]

# Method 1 set map parameters
map = (
    Map(init_opts=opts.InitOpts(bg_color="#FFFAFA", theme=ThemeType.ESSOS,width=1000))
        .add("Confirmed number", data)
        .set_global_opts(
        title_opts=opts.TitleOpts(title="fungis-Epidemic map based on the data of dingxiangyuan"),
        visualmap_opts=opts.VisualMapOpts(max_=2000),#Maximum interval value, varies by graph
    )
)
map.render(path="./html/Map of epidemic population interval in China 1.html")

    1. Statistics of epidemic situation combination in China based on the data of dingxiangyuan - fengis-2020 / 02 / 10
  • Implementation code
# -*- coding: utf-8 -*-

"""
@Author  : fungis@163.com
@Time    : 2020/2/9 13:12
"""


from pyecharts import options as opts #Import configuration item
from pyecharts.charts import Bar,Line,Grid

# Built in theme types can be found in pyecharts.globals.ThemeType
from pyecharts.globals import ThemeType

columns = ['Jiangsu', 'Anhui', 'Hunan', 'Henan', 'Zhejiang', 'Guangdong', 'Tianjin', 'Inner Mongolia', 'Beijing', 'Shaanxi', 'Guangxi', 'Ningxia', 'Guizhou', 'Shanghai', 'Jiangxi', 'Fujian', 'Xinjiang', 'Sichuan',
           'Yunnan', 'Hainan', 'Shandong', 'Jilin', 'Heilongjiang', 'Hebei', 'Hong Kong', 'Chongqing', 'Shanxi', 'Gansu', 'Hubei', 'Liaoning', 'Taiwan', 'Macao', 'Qinghai', 'Tibet']
confirmedCount = [492, 830, 879, 1073, 1092, 1151, 94, 58, 337, 213, 210, 49, 109, 295, 771, 261, 49, 405, 141, 136,
                  459, 80, 331, 218, 36, 468, 119, 83, 29631, 107, 18, 10, 18, 1]
curedCount = [80, 80, 194, 179, 205, 148, 4, 5, 44, 26, 18, 13, 7, 44, 102, 35, 0, 76, 18, 19, 63, 12, 15, 35, 0, 51,
              25, 16, 1795, 12, 1, 1, 3, 0]
deadCount = [0, 3, 1, 6, 0, 1, 1, 0, 2, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 3, 1, 1, 7, 2, 1, 2, 0, 2, 871, 0, 0, 0, 0, 0]


#Define three chart objects
grid = Grid()
bar = Bar()
line = Line()

#Display theme settings
grid.theme = ThemeType.PURPLE_PASSION
grid.width = 1200
#Set data and chart parameters
bar.height=1000
bar.add_xaxis(columns)
bar.add_yaxis("Cure number",curedCount)
bar.add_yaxis("death toll",deadCount)
bar.set_global_opts(title_opts=opts.TitleOpts("Distribution of the number of confirmed cases in China-fungis")
                   ,tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross") # Cross pointing tool
                   )
bar.extend_axis(yaxis=opts.AxisOpts(type_="value",
                                     name="Number",
                                     min_=0,
                                     max_=35000,
                                     position="right",
                                     axislabel_opts=opts.LabelOpts(formatter="{value} people"),
                                     ))
# Add Y axis on bar and select corresponding axis on line graph
line.add_xaxis(columns)
line.add_yaxis("Confirmed number",confirmedCount,yaxis_index = 1)
# Add line to bar
bar.overlap(line)
# Here, if you don't need grid, you can directly set bar format, and then display bar
#bar.render_notebook()
grid.add(chart = bar,grid_opts = opts.GridOpts(),is_control_axis_index = True)

grid.render(path='./China Portfolio 1.html')
    1. Distribution of the number of confirmed cases in Henan Province Based on the data of dingxiangyuan-fengis-2020 / 02 / 10
  • Implementation code
# -*- coding: utf-8 -*-

"""
@Author  : fungis@163.com
@Time    : 2020/2/9 13:53
"""

from pyecharts.charts import Map
from pyecharts import options as opts
from pyecharts.globals import ThemeType  # theme

# Relevant data of each city
data = [['Xinyang City', 220], ['Nanyang City', 134], ['Zhengzhou City', 130], ['Zhumadian City', 123], ['Shangqiu City', 83], ['Zhoukou', 65], ['Pingdingshan City', 52], ['Xinxiang City', 46],
        ['Anyang City', 45], ['Xuchang City', 31], ['Luohe City', 30], ['Luoyang City', 27], ['Jiaozuo City', 25], ['Kaifeng City', 24], ['Hebi City', 17], ['Puyang City', 10],
        ['Sanmenxia City', 7], ['Jiyuan City', 4]]
cityName = ['Xinyang City', 'Nanyang City', 'Zhengzhou City', 'Zhumadian City', 'Shangqiu City', 'Zhoukou', 'Pingdingshan City', 'Xinxiang City', 'Anyang City', 'Xuchang City', 'Luohe City', 'Luoyang City', 'Jiaozuo City', 'Kaifeng City', 'Hebi City',
            'Puyang City', 'Sanmenxia City', 'Jiyuan City']
confirmedCount = [220, 134, 130, 123, 83, 65, 52, 46, 45, 31, 30, 27, 25, 24, 17, 10, 7, 4]
curedCount = [28, 28, 34, 14, 9, 11, 12, 6, 10, 2, 6, 2, 1, 1, 3, 0, 3, 0]
deadCount = [0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

map = (
    # The width, height, background color and theme of the canvas can be set in the initialization configuration item
    Map(init_opts=opts.InitOpts(bg_color="#FFFAFA", theme=ThemeType.ROMANTIC, width=1000))
        .add("Confirmed number", data, "Henan", is_map_symbol_show=False, )  # Set whether to display small red dots on the map
        .set_global_opts(
        # Title configuration item. pos_left can take center, left, right, 5% and so on
        title_opts=opts.TitleOpts(title="Distribution of the number of confirmed cases in Henan-fungis", pos_left="left"),
        visualmap_opts=opts.VisualMapOpts(
            is_piecewise=True,  # Set whether to display in segments
            # Customize the range of each paragraph, as well as the text of each paragraph, and the special style of each paragraph. For example:
            pieces=[
                {"min": 201, "label": '>200 people', "color": "#e55039"},  # If max is not specified, it means that max is infinite.
                {"min": 101, "max": 200, "label": '101-200 people', "color": "#FF4500"},
                {"min": 51, "max": 100, "label": '51-100 people', "color": "#FF7F50"},
                {"min": 10, "max": 50, "label": '10-50 people', "color": "#FFA500"},
                {"min": 1, "max": 9, "label": '1-9 people', "color": "#FFDEAD"},
            ],
            # Text at both ends, such as ['high ',' low '].
            range_text=['high', 'low'],
        ),
    )
)
map.render(path="./Distribution of confirmed cases in Henan Province 1.html")

    1. Combined statistics of epidemic situation in Henan Province Based on the data of dingxiangyuan - fengis-2020 / 02 / 10
  • Implementation code
# -*- coding: utf-8 -*-

"""
@Author  : fungis@163.com
@Time    : 2020/2/9 13:53
"""

from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType

columns = ['Xinyang City', 'Nanyang City', 'Zhengzhou City', 'Zhumadian City', 'Shangqiu City', 'Zhoukou', 'Pingdingshan City', 'Xinxiang City', 'Anyang City', 'Xuchang City', 'Luohe City', 'Luoyang City', 'Jiaozuo City', 'Kaifeng City', 'Hebi City',
            'Puyang City', 'Sanmenxia City', 'Jiyuan City']
confirmedCount = [220, 134, 130, 123, 83, 65, 52, 46, 45, 31, 30, 27, 25, 24, 17, 10, 7, 4]
curedCount = [28, 28, 34, 14, 9, 11, 12, 6, 10, 2, 6, 2, 1, 1, 3, 0, 3, 0]
deadCount = [0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

bar = (
    Bar(init_opts=opts.InitOpts(bg_color="#FFFAFA", theme=ThemeType.LIGHT, width=1200))
        .add_xaxis(columns)
        .add_yaxis("Cure number", curedCount)
        .add_yaxis("death toll", deadCount)
        .extend_axis(yaxis=opts.AxisOpts(type_="value",
                                         name="Number",
                                         position="left",
                                         axislabel_opts=opts.LabelOpts(formatter="{value} people"),
                                         ))
        .set_global_opts(title_opts=opts.TitleOpts(title="fungis-Henan epidemic situation map based on Ding Xiangyuan data"))
)

bar.render(path="./Henan histogram 1.html")

In addition, the epidemic data of dingxiangyuan Download address For:

https://github.com/BlankerL/DXY-2019-nCoV-Data/blob/master/json/DXYArea.json

This is a json data that needs to be parsed. In the next issue, I will update how to automatically parse it into the corresponding mapping format. Like friends can point to a concern, the follow-up will continue to update, wonderful infinite ^ -^

46 original articles published, 68 praised, 3403 visited
Private letter follow

Tags: JSON less github

Posted on Mon, 10 Feb 2020 08:53:52 -0500 by dcro2