Matplotlib

Notes while using python/matplotlib.

Chinese font in plot on MacOS

1. Run the following python code to get a list of installed fonts.

import matplotlib
print(sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist]))

2. Choose one font and vim ~/.matplotlib/matplotlibrc

3. Add the following line:

font.family: .PingFang SC
axes.unicode_minus: False

Not installed as a framework

vim ~/.matplotlib/matplotlibrc

Add the following line:

backend: TkAgg

Last updated

Was this helpful?