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

相关推荐
2501_944452235 小时前
字数统计 Cordova 与 OpenHarmony 混合开发实战
python
骚戴5 小时前
2025 Python AI 实战:零基础调用 LLM API 开发指南
人工智能·python·大模型·llm·api·ai gateway
kobe_OKOK_5 小时前
tdeinge REST API 客户端
python·缓存·django
io_T_T6 小时前
Python os库 os.walk使用(详细教程、带实践)
python
李小白杂货铺6 小时前
国产操作系统/Linux桌面系统使用手记
ubuntu·国产操作系统·银河麒麟·统信·国产cpu·linux桌面系统·国产硬件平台
TonyLee0177 小时前
使用argparse模块以及shell脚本
python
Blossom.1187 小时前
Prompt工程与思维链优化实战:从零构建动态Few-Shot与CoT推理引擎
人工智能·分布式·python·智能手机·django·prompt·边缘计算
love530love9 小时前
Windows 11 下 Z-Image-Turbo 完整部署与 Flash Attention 2.8.3 本地编译复盘
人工智能·windows·python·aigc·flash-attn·z-image·cuda加速
MediaTea9 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer9 小时前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas