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

相关推荐
花酒锄作田3 小时前
Postgres - Listen/Notify构建轻量级发布订阅系统
python·postgresql
Thomas.Sir4 小时前
第二章:LlamaIndex 的基本概念
人工智能·python·ai·llama·llamaindex
m0_694845574 小时前
Dify部署教程:从AI原型到生产系统的一站式方案
服务器·人工智能·python·数据分析·开源
李昊哲小课5 小时前
Python办公自动化教程 - 第7章 综合实战案例 - 企业销售管理系统
开发语言·python·数据分析·excel·数据可视化·openpyxl
不知名的老吴6 小时前
返回None还是空集合?防御式编程的关键细节
开发语言·python
李昊哲小课6 小时前
Python办公自动化教程 - 第5章 图表创建 - 让数据可视化
python·信息可视化·数据分析·数据可视化·openpyxl
chushiyunen6 小时前
python pygame实现贪食蛇
开发语言·python·pygame
Dream of maid6 小时前
Python-基础2(流程控制)
python
绛橘色的日落(。・∀・)ノ6 小时前
Matplotlib 第四章 文字图例尽眉目
matplotlib
starvapour6 小时前
Ubuntu系统下基于终端的音频相关命令
linux·ubuntu·音视频