Skip to content

Matplotlib Figure Translation Tools

Humphrey Yang edited this page Oct 1, 2024 · 1 revision

Using Chinese font

To show Chinese font in the graphs, we need to run the code

import matplotlib as mpl
FONTPATH = "fonts/SourceHanSerifSC-SemiBold.otf"
mpl.font_manager.fontManager.addfont(FONTPATH)
plt.rcParams['font.family'] = ['Source Han Serif SC']

to import the Chinese font

Mapping across countries

In the dataset subfolder, a mapping between the country/region name and the Chinese name under ISO standard is available for the mapping

Year-month presentation

To show the Chinese year and month in the plot, we can use

ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y年%m月'))

Clone this wiki locally