ubuntu下解决matplotlib生成图片中文乱码
2018-01-04 11:19
501 查看
简介
本文主要介绍如何在ubuntu下解决matplotlib生成图片中文乱码问题。如下图解决思路
准备中文字体matplotlib指定字体为中文字体
清空matplotlib使配置生效
准备中文字体
下载中文ttf文件,也可以从windows操作系统里复制。 如 黑体(点击下载)
双击安装
终端下运行命令
fc-list :lang=zh-cn,查看中文字体对应的
配置名。如黑体对应的名字为
SimHei.
matplotlib指定字体为中文字体
复制中文字体文件到matplotlib的fonts/ttf目录。完整的目录为
/usr/local/lib/python*/dist-packages/matplotlib/mpl-data/fonts/ttf
修改配置
/usr/local/lib/python*/dist-packages/matplotlib/mpl-data/matplotlibrc文件
# 搜索font.family配置项,将其#注释去掉,并将:号后面的值改为字段对应的名字。 font.family : SimHei # 搜索axes.unicode_minus配置项,将其#注释去掉,并将:号后面的值改为False axes.unicode_minus : False
保存退出
清空matplotlib使配置生效
rm ~/.cache/matplotlib -R
最终效果图
本文用到的测试代码
import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 10, 0.1) y = x * 2 plt.title("一元一次函数") plt.plot(x, y) plt.show()
查看原文:https://www.huuinn.com/archives/533
更多技术干货:风匀坊
关注公众号:风匀坊
相关文章推荐
- 解决matplotlib中文乱码问题(Ubuntu16.04)
- Ubuntu下matplotlib绘图中文乱码问题的解决
- ubuntu系统下matplotlib中文乱码问题的解决方法
- 解决matplotlib中文乱码问题
- matplotlib图例中文乱码解决
- matplotlib解决中文乱码问题
- Python 3下Matplotlib画图中文显示乱码的解决方法
- Ubuntu环境下 matplotlib 图例中文乱码
- ubuntu16.04安装matplotlibm导致中文乱码的问题解决
- ubuntu系统下matplotlib中文乱码问题
- matplotlib中文乱码解决方法
- 一次解决Matplotlib绘图中的中文乱码问题
- matplotlib中文乱码解决方法
- python matplotlib中文显示乱码解决
- matplotlib中画图显示中文,但保存为图片后中文乱码
- 在matplotlib中,解决中文乱码问题
- Ubuntu下matplotlib中文无法显示的解决方法
- 解决matplotlib中文乱码问题(Windows)
- matplotlib中文乱码解决方法
- ubuntu下matplotlib画图中文乱码问题