matplotlib 中文显示

下面为博客摘要,详细内容请看http://keke046.github.io/2022/04/06/matplotlib-chinese/

matplotlib 中文显示

matplotlib每次更新似乎中文字体都会炸。写了一个bash脚本来自动修复matplotlib字体,只适用于linux。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
MPL_RC="`python -c 'import matplotlib; print(matplotlib.matplotlib_fname())'`"
MPL_FONTS=`dirname "${MPL_RC}"`/fonts
MPL_CACHE="`python -c 'import matplotlib; print(matplotlib.get_cachedir())'`"
TTF_URL="https://raw.githubusercontent.com/Yehrin/FontLibrary/master/simhei.ttf"
[ -f ${MPL_FONTS}/ttf/simhei.ttf ] || wget "${TTF_URL}" -P "${MPL_FONTS}/ttf" -q --show-progress
cp ${MPL_RC} ${MPL_RC}.bak
cat ${MPL_RC}.bak | \
sed -e 's/#font.family:/font.family:/g' | \
sed -e 's/font.family: *SimHei,/font.family:/g' | \
sed -e 's/font.family:/font.family: SimHei,/g' | \
sed -e 's/#axes.unicode_minus:/axes.unicode_minus:/g'| \
sed -e 's/axes.unicode_minus: True/axes.unicode_minus: False/g' |\
sed -e 's/#mathtext.fontset: dejavusans/mathtext.fontset: cm/g' > ${MPL_RC}
rm -rf "${MPL_CACHE}"






com/Yehrin/FontLibrary/master/simhei。matplotlib_fname())'`"MPL_FONTS=`dirname "${MPL_RC}"`/fontsMPL_CACHE="`python -c 'import matplotlib; print(matplotlib。!-- indicate-the-source --# matplotlib 中文显示matplotlib每次更新似乎中文字体都会炸。fontset: dejavusans/mathtext。bak | \sed -e 's/#font。family:/g' | \sed -e 's/font。ttf"[ -f ${MPL_FONTS}/ttf/simhei。family:/font。unicode_minus: False/g' |\sed -e 's/#mathtext。fontset: cm/g' ${MPL_RC}rm -rf "${MPL_CACHE}"```!--more--。get_cachedir())'`"TTF_URL="https://raw。ttf ] || wget "${TTF_URL}" -P "${MPL_FONTS}/ttf" -q --show-progresscp ${MPL_RC} ${MPL_RC}。写了一个bash脚本来自动修复matplotlib字体,只适用于linux。githubusercontent。family:/font。family:/g' | \sed -e 's/font。```bashMPL_RC="`python -c 'import matplotlib; print(matplotlib。family: SimHei,/g' | \sed -e 's/#axes。unicode_minus:/g'| \sed -e 's/axes。unicode_minus: True/axes。family: *SimHei,/font。unicode_minus:/axes。bakcat ${MPL_RC}