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

相关推荐
郝学胜-神的一滴17 分钟前
Effective Python 第52条:用subprocess模块优雅管理子进程
linux·服务器·开发语言·python
万粉变现经纪人1 小时前
如何解决 pip install 编译报错 ‘cl.exe’ not found(缺少 VS C++ 工具集)问题
开发语言·c++·人工智能·python·pycharm·bug·pip
r***11331 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
___波子 Pro Max.1 小时前
Python类型注解详解与应用
python
1***Q7842 小时前
Python增强现实案例
开发语言·python·ar
Q26433650232 小时前
【有源码】spark与hadoop-情感挖掘+画像建模的携程酒店评价数据分析可视化系统-基于机器学习的携程酒店评价情感分析与竞争态势可视化
大数据·hadoop·python·机器学习·数据分析·spark·毕业设计
倚肆3 小时前
Spring Boot 中的 Bean 与自动装配详解
spring boot·后端·python
不剪发的Tony老师3 小时前
PyScripter:一款免费开源、功能强大的Python开发工具
ide·python
q***06294 小时前
PHP进阶-在Ubuntu上搭建LAMP环境教程
开发语言·ubuntu·php
u***42074 小时前
Ubuntu介绍、与centos的区别、基于VMware安装Ubuntu Server 22.04、配置远程连接、安装jdk+Tomcat
java·ubuntu·centos