Ubuntu16.04 python matplotlib 输出轴标签出现中文乱码

  • 问题:坐标轴打印中文时,显示会乱码
python 复制代码
import matplotlib.pyplot as plt
plt.ylabel('时间刻度')
  • 原因:matplotlib里面没有中文字体
  • 解决方法:下载SimHei字体,快捷方法是使用everything直接在windows搜索simhei.ttf,再拖进Ubuntu就可以了
  • 最后在程序里面加入字体的路径就可以了
python 复制代码
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.xlabel('横轴标签', fontproperties=FontProperties(fname='/home/your_path/simhei.ttf',))
plt.ylabel('纵轴标签', fontproperties=FontProperties(fname='/home/your_path/simhei.ttf'))

Reference

相关推荐
li99yo11 分钟前
3DGS的复现
图像处理·pytorch·经验分享·python·3d·conda·pip
Dontla4 小时前
用pip install -e .开发Python包时,Python项目目录结构(项目结构)(可编辑安装editable install)
python·pip
Thomas.Sir4 小时前
第三章:Python3 之 字符串
开发语言·python·字符串·string
枫桥骤雨5 小时前
我的龙虾日记
ubuntu·openclaw
威联通网络存储5 小时前
告别掉帧与素材损毁:威联通 QuTS hero 如何重塑影视后期协同工作流
前端·网络·人工智能·python
Dxy12393102166 小时前
Python 根据列表中某字段排序:从基础到进阶
开发语言·windows·python
splage6 小时前
Java进阶——IO 流
java·开发语言·python
cliffordl6 小时前
设计模式(python)
python·设计模式
always_TT6 小时前
从Python_Java转学C语言需要注意什么?
java·c语言·python