Frontend Development 5 min read

Using pyecharts to Create Various Map Visualizations in Python

This tutorial introduces the Python pyecharts library for creating various map visualizations with Echarts, explains how the code generates HTML files, and provides complete example functions for basic, label‑less, continuous and piecewise visual maps, world and regional maps, plus guidance for using real data.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Using pyecharts to Create Various Map Visualizations in Python

pyecharts is a Python library that generates Echarts charts, which is a JavaScript data‑visualization library from Baidu.

The article explains that running pyecharts code creates an HTML file (renderer.html) in the current directory, which can be opened in a browser to view the chart.

It introduces several map examples, including a basic map, a map without labels, a map with a continuous visual map, a piecewise visual map, a world map, and a Guangdong province map, showing how to customize titles and visual map options.

Below is the complete Python code used to generate the six map charts, wrapped in ... tags.

<code>from pyecharts import options as opts
from pyecharts.charts import Map, Page
from pyecharts.faker import Collector, Faker
C = Collector()

@C.funcs
def map_base() -> Map:
    c = (
        Map()
        .add("商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
        .set_global_opts(title_opts=opts.TitleOpts(title="Map-基本示例"))
    )
    return c

@C.funcs
def map_without_label() -> Map:
    c = (
        Map()
        .add("商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="Map-不显示Label"))
    )
    return c

@C.funcs
def map_visualmap() -> Map:
    c = (
        Map()
        .add("商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Map-VisualMap(连续型)"),
            visualmap_opts=opts.VisualMapOpts(max_=200),
        )
    )
    return c

@C.funcs
def map_visualmap_piecewise() -> Map:
    c = (
        Map()
        .add("商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Map-VisualMap(分段型)"),
            visualmap_opts=opts.VisualMapOpts(max_=3, is_piecewise=True),
        )
    )
    return c

@C.funcs
def map_world() -> Map:
    c = (
        Map()
        .add("商家A", [list(z) for z in zip(Faker.country, Faker.values())], "world")
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Map-世界地图"),
            visualmap_opts=opts.VisualMapOpts(max_=200),
        )
    )
    return c

@C.funcs
def map_guangdong() -> Map:
    c = (
        Map()
        .add("商家A", [list(z) for z in zip(Faker.guangdong_city, Faker.values())], "广东")
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Map-广东地图"),
            visualmap_opts=opts.VisualMapOpts(),
        )
    )
    return c

Page().add(*[fn() for fn, _ in C.charts]).render()
</code>

The generated HTML files can be opened in a browser to view the maps, and the article also shows how to replace the fake data with real data by modifying the .add() arguments and adjusting the visual map's max parameter.

PythonTutorialData VisualizationEChartspyechartsMap VisualizationCharting
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.