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

相关推荐
江华森23 分钟前
Python 进阶编程实战 — 从多版本环境到百万级登录系统
python
C+-C资深大佬25 分钟前
python while循环
服务器·开发语言·python
zh路西法2 小时前
【现代控制理论与卡尔曼滤波】从状态空间到Python仿真实现
开发语言·python
Vodka~2 小时前
WSL2 + RViz GPU渲染机械臂
人工智能·python
8Qi82 小时前
hello-agents学习笔记--Memory让Agent拥有记忆
人工智能·python·llm·agent·ai编程·vibecoding
Esaka_Forever3 小时前
Python 完整内存管理机制详解
开发语言·python·spring
Weigang3 小时前
用 LlamaIndex 做 RAG 前,先把 Reader、Index、Retriever 的边界写清楚
人工智能·python·开源
小九九的爸爸3 小时前
前端入门Agent开发,掌握这些Python数据基础就够啦
python·agent
风之所往_3 小时前
Python 3.9 新特性全面总结
python