Fundamentals 7 min read

Creating a Hangzhou Walking Routes Heatmap and a Gradient Scatter Chart with Pyecharts

This tutorial demonstrates how to use the Python Pyecharts library to fetch Hangzhou walking route data, render it on a Baidu map heatmap, and build a gradient‑styled scatter plot comparing life expectancy and GDP for multiple countries in 1990 and 2015.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Creating a Hangzhou Walking Routes Heatmap and a Gradient Scatter Chart with Pyecharts

This article shows how to implement two visualization examples using the Pyecharts library: a heatmap of popular walking routes in Hangzhou displayed on a Baidu map, and a gradient scatter plot illustrating the relationship between life expectancy and GDP for various countries in 1990 and 2015.

Hangzhou Walking Routes Heatmap

Before running the code you need a Baidu Map developer AK, which can be obtained from the Baidu Map Open Platform. The data source is the JSON file hangzhou-tracks.json .

<code>from pyecharts import options as opts
from pyecharts.charts import BMap
from pyecharts.globals import ChartType, SymbolType, ThemeType
import requests

# Fetch data
r = requests.get('https://echarts.baidu.com/examples/data/asset/data/hangzhou-tracks.json')
data = r.json()

data_pair = []

# Create BMap object
bmap = BMap()

for i, item in enumerate([j for i in data for j in i]):
    # Add coordinate points
    bmap.add_coordinate(i, item['coord'][0], item['coord'][1])
    data_pair.append((i, 1))

bmap.add_schema(
    # You must provide your own AK
    baidu_ak='VtTfLEPhrSmI34foXXozmE441uDOSA7V',
    # Map zoom level
    zoom=14,
    # Center coordinates
    center=[120.13066322374, 30.240018034923])

# Add data as heatmap
bmap.add("门店数", data_pair, type_='heatmap')

# Hide data labels
bmap.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

bmap.set_global_opts(
    visualmap_opts=opts.VisualMapOpts(min_=0, max_=50, range_color=['blue', 'blue', 'green', 'yellow', 'red']),
    legend_opts=opts.LegendOpts(is_show=False),
    title_opts=opts.TitleOpts(title="杭州热门步行路线"))

# Render in notebook (or use bmap.render() in other environments)
bmap.render_notebook()
</code>

The resulting map visualizes the density of walking routes across Hangzhou.

Gradient Effect Scatter Plot

<code>from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode

# Data: life expectancy, GDP, population, country, year
data = [
    [
        [[28604,77,17096869,'Australia',1990], [31163,77.4,27662440,'Canada',1990], ...],
        [[44056,81.8,23968973,'Australia',2015], [43294,81.7,35939927,'Canada',2015], ...]
    ]
]

scatter = (Scatter()
    .add_xaxis([i[0] for i in data[0]])
    .add_yaxis("1990年", [[i[1], i[3], i[2]] for i in data[0]],
        color=JsCode("""new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{offset: 0, color: 'rgb(251, 118, 123)'}, {offset: 1, color: 'rgb(204, 46, 72)'}])"""))
    .add_yaxis("2015年", [[i[1], i[3], i[2]] for i in data[1]],
        color=JsCode("""new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{offset: 0, color: 'rgb(129, 227, 238)'}, {offset: 1, color: 'rgb(25, 183, 207)'}])"""))
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="1990 与 2015 年各国家人均寿命与 GDP"),
        tooltip_opts=opts.TooltipOpts(formatter=JsCode("function (param) {return param.data[2];}")),
        xaxis_opts=opts.AxisOpts(type_="value", splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(type_="value", is_scale=True, splitline_opts=opts.SplitLineOpts(is_show=True)),
        visualmap_opts=opts.VisualMapOpts(is_show=False, type_='size', min_=20194354, max_=1154605773)
    ))

scatter.render_notebook()
</code>

The scatter chart uses radial gradients to differentiate the two years and encodes population size via point size, providing a clear visual comparison of life expectancy and GDP across countries.

Both visualizations are intended for learning purposes; the original images are shown in the article.

Pythongradientdata-visualizationpyechartsheatmapScatter Plot
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.