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

相关推荐
FriendshipT7 小时前
Ultralytics:解读CBLinear模块
人工智能·pytorch·python·深度学习·目标检测
AI开发发烧友7 小时前
LangGraph多Agent协作实战:以物流售前场景为例的5 Agent工作流设计
python
码云骑士7 小时前
70-多Agent协作-CrewAI-AutoGen-角色分工与信息传递协议
python
Hachi被抢先注册了8 小时前
Skills总结
python
用户0332126663678 小时前
使用 Python 在 PowerPoint 中创建折线图和条形图
python
benchmark_cc8 小时前
如何用 Python 进行多周期 K 线合成与时区对齐?基于 QuantDash 与 Pandas 的量化数据清洗实战(附 GitHub 源码)
开发语言·python·github·盯盘·pandas·quantdash·量化数据
不如语冰8 小时前
AI大模型入门-参数的传递
数据结构·人工智能·pytorch·python
用户6760840656178 小时前
GraphBLAS_01_图的稀疏表示
python
小陈工8 小时前
第7篇:Django框架核心原理与实战深度解析(下)
后端·python·面试
用户298698530149 小时前
Python 数据处理:XML 与 Excel 互转的实用指南
后端·python·excel