Ubuntu环境下matplotlib图例中文乱码

本文前提条件是已经安装好matplotlib ,至于matplotlib是什么,怎么安装,本文不予介绍。

,

 Ubuntu环境下matplotlib图例中文乱码

 Ubuntu环境下matplotlib图例中文乱码

,

,

,

首先在,Windows 盘区下,找到,,微软雅黑,,的字体文件:

 Ubuntu环境下matplotlib图例中文乱码

,

,

其次,找到matplotlab 字体库,文件夹,,,或者,,系统字体库文件夹

,

matplotlab 字体库,文件夹

 Ubuntu环境下matplotlib图例中文乱码

,

 Ubuntu环境下matplotlib图例中文乱码

,

,

系统字体库文件夹

 Ubuntu环境下matplotlib图例中文乱码

,

把字体文件拷贝到这两个路径下的任何一个都可以。

,

,

然后,找到matplotlib 配置文件

 Ubuntu环境下matplotlib图例中文乱码

,

,

可以直接修改该文件,或者

 Ubuntu环境下matplotlib图例中文乱码

,

,

然后,,修改配置文件。

编辑该配置文件,找到,font.family ,将注释去掉,在下面的,font.sans 作用;serif : Bitstream  Vera 无,,Lucida 格兰德,Verdana,,,清醒,日内瓦,Arial, Helvetica,, Avant 加利,sans 作用;serif 加上中文字体,微软YaHei 。

 Ubuntu环境下matplotlib图例中文乱码

,

,

,

最后,清除缓存

做了上面的更改,发现并没有什么用。

到,~/.cache/matplotlib下的文件删掉,就好了。

,

,

,

 Ubuntu环境下matplotlib图例中文乱码

,

,

,

,


Ubuntu环境下matplotlib图例中文乱码