方法一
字体更新
python
查看缓存目录&删除缓存目录
import matplotlib
matplotlib.get_cachedir()
rm -rf 目录
查所字体配置文件matplotlibrc路径
import matplotlib
print(matplotlib.matplotlib_fname())
修改配置文件
#font.family: sans-serif #打开
#font.sans-serif: DejaVu Sans #添加SimHei,
#axes.unicode_minus: False 修改为False
或者
sed -i "s/\#font.family: sans-serif/font.family: sans-serif/g" /opt/conda/lib/python3.8/site-packages/matplotlib/mpl-data/matplotlibrc
sed -i "s/\#font.sans-serif: DejaVu Sans/font.sans-serif: SimHei, DejaVu Sans/g" /opt/conda/lib/python3.8/site-packages/matplotlib/mpl-data/matplotlibrc
sed -i "s/\#axes.unicode_minus: True/axes.unicode_minus: False/g" /opt/conda/lib/python3.8/site-packages/matplotlib/mpl-data/matplotlibrc
#复制字体文件到容器中
#查找字体目录在哪里
find / -name *.ttf
复制字体到容器中
docker cp F:/SimHei.ttf pycharm:/home/smartide/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/
备注:
复制配置文件到本地修改
docker cp 540b7e0945e5:/opt/conda/lib/python3.8/site-packages/matplotlib/mpl-data/matplotlibrc d:/
方法二
#查找字体目录在哪里
find / -name *.ttf
复制字体到容器中
docker cp F:/SimHei.ttf pycharm:/home/smartide/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/
docker cp F:/SimHei.ttf pycharm:/home/smartide/anaconda3/pkgs/matplotlib-base-3.1.3-py37hef1b27d_0/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/
#删除缓存目录
python
matplotlib.get_cachedir()
rm -rf 目录
在代码里指定字体
#设置字体为楷体
1.
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
2.或者
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
3.或者
#from matplotlib import font_manager as fm, rcParams
import matplotlib as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
代码里指定字体
matplotlib.rcParams['font.sans-serif'] = ['SimHei']