mac font size:Chinese font problem in matplotlib's rcParams file and global font size control in pictures-Font Tutorial免费ppt模版下载-道格办公

Chinese font problem in matplotlib's rcParams file and global font size control in pictures

1 Two commonly used configurations of matplotlib
1.1 Solve the problem that the picture cannot generate Chinese text
Using this command, the Chinese in the picture can be displayed, and the default is that Chinese cannot be displayed of.

Of course, you must have fonts first: download Chinese fonts (black body, check the system version , select MAC version)
SimHei Download

from pylab import mplmpl.rcParams['font.sans-serif'] = ['SimHei'] # Set matplotlib to display Chinese mpl.rcParams['axes.unicode_minus'] = False< /pre>


1.2 Configure the font size of all text in the picture
Using this command, you can adjust the size of all the fonts in the picture to solve the problem that the text in the original image is too small.

from pylab import mplmpl.rcParams['font.size'] = 13

2 Modify the global configuration of matplotlib

(If you use the mat in that environment, you can change that one, anyway, I will change it conda virtual environment)

My mac os path:

Since I am using python3 installed by anaconda, the path is /Users/anaconda3/ lib/env/****/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf,

Copy the downloaded SimHei.ttf to the ttf folder

Modify the configuration file matplotlibrc, /python3.6/site-packages/matplotlib/mpl Under the -data directory, modify the following three configurations

font.family: sans-serif font.sans-serif: SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serifaxes.unicode_minus: False

3 The most important step is here, change the configuration It will not take effect after that, you need to reload the font, open Python on the command line, and run the following code:

from matplotlib.font_manager import _rebuild _rebuild() #reload it

Articles are uploaded by users and are for non-commercial browsing only. Posted by: Lomu, please indicate the source: https://www.daogebangong.com/en/articles/detail/Chinese%20font%20problem%20in%20matplotlibs%20rcParams%20file%20and%20global%20font%20size%20control%20in%20pictures.html

Like (810)
Reward 支付宝扫一扫 支付宝扫一扫
single-end

Related Suggestion