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

相关推荐
chushiyunen24 分钟前
python rest请求、requests
开发语言·python
cTz6FE7gA24 分钟前
Python异步编程:从协程到Asyncio的底层揭秘
python
baidu_huihui31 分钟前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳33 分钟前
Python从入门到精通day63
开发语言·python
lbb 小魔仙33 分钟前
Python_RAG知识库问答系统实战指南
开发语言·python
FreakStudio1 小时前
MicroPython LVGL基础知识和概念:底层渲染与性能优化
python·单片机·嵌入式·电子diy
素玥2 小时前
实训5 python连接mysql数据库
数据库·python·mysql
一叶知秋yyds2 小时前
Ubuntu 虚拟机安装 OpenClaw 完整流程
linux·运维·ubuntu·openclaw
zzzzls~2 小时前
Python 工程化: 用 Copier 打造“自我进化“的项目脚手架
开发语言·python·copier