In [ ]:
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import GeoType
In [2]:
# Read the Excel file
df = pd.read_excel("updated_county.xlsx")
In [3]:
# Create a geographical coordinate plot and set the width and height
geo = Geo(init_opts=opts.InitOpts(width="500px", height="500px"))
# Add a map type
geo.add_schema(maptype="china",is_roam=False)
Out[3]:
<pyecharts.charts.basic_charts.geo.Geo at 0x17713fcbee0>
In [4]:
# Add coordinates from DataFrame
for index, row in df.iterrows():
geo.add_coordinate(row['county'], row['longitude'], row['latitude'])
In [5]:
# "Add a scatter plot to visualize the distribution.
geo.add(
"",
[(row['county'], 88) for index, row in df.iterrows()],
type_=GeoType.SCATTER, # Chart type is scatter plot
symbol_size=3 # Size of the points
)
Out[5]:
<pyecharts.charts.basic_charts.geo.Geo at 0x17713fcbee0>
In [6]:
# Set global options
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
geo.set_global_opts(
title_opts=opts.TitleOpts(title="Distribution Map of \nIntangible Cultural Heritage in China"),
visualmap_opts=opts.VisualMapOpts(is_show=False),
)
Out[6]:
<pyecharts.charts.basic_charts.geo.Geo at 0x17713fcbee0>
In [7]:
# Render the map.
geo.render_notebook()
Out[7]:
Although scatter plots can display the exact locations of each item, they are not visually appealing (they may even trigger trypophobia). Therefore, we are attempting to visualize using heat maps.
In [8]:
#Replace "SCATTER" with "HEATMAP" and adjust the value of each point to control the "intensity" of the heat map for better visual effects.
geo = Geo()
geo = Geo(init_opts=opts.InitOpts(width="600px", height="600px"))
geo.add_schema(maptype="china",is_roam=False)
geo.add(
"",
[(row['county'], 1) for index, row in df.iterrows()],
type_=GeoType.HEATMAP
)
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
geo.set_global_opts(
title_opts=opts.TitleOpts(title="Distribution Map of \nIntangible Cultural Heritage in China"),
visualmap_opts=opts.VisualMapOpts(is_show=False),
)
geo.render_notebook()
Out[8]:
In [ ]: