Python matplotlib pyplot中title() xlabel() ylabel()无法显示在中文(方框乱码)的解决办法
来源:互联网 发布:软件资格考试怎么报名? 编辑:程序博客网 时间:2024/04/30 07:17
Python matplotlib包其实是支持unicode的,但是我在实验中无法正常显示中文,比如说在pyplot.title()中输出中文,我试过以下几种方法均不奏效:
pyplot.title('中文')
pyplot.title("中文")
pyplot.title(u'中文')
pyplot.title(u"中文")
pyplot.title(u'\u4e2d\u6587') # (unicode编码)
pyplot.title('\u4e2d\u6587')
pyplot.title('\xe4\xb8\xad\xe6\x96\x87') # (utf-8编码)
原来是matplotlib.pyplot在显示时无法找到合适的字体,故显示乱码(我的显示为方框)
解决办法:
添加相关包,指定相关字体
from matplotlib import pyplotfrom matplotlib.font_manager import FontPropertiesfont_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)pyplot.title(u'中文', fontproperties=font_set)pyplot.xlabel(u'中文', fontproperties=font_set)pyplot.ylabel(u'中文', fontproperties=font_set)
0 0
- Python matplotlib pyplot中title() xlabel() ylabel()无法显示在中文(方框乱码)的解决办法
- Python matplotlib pyplot中title() xlabel() ylabel()无法显示在中文(方框乱码)的解决办法
- matplotlib之pyplot中ylabel和xlabel方法详解
- python2,绘图title,xlabel,ylabel出现中文乱码
- python matplotlib.pyplot 显示中文title等参数
- matlab 图片显示 imshow axis title xlabel ylabel plot
- Matlab中xlabel和ylabel的用法
- python matplotlib.pyplot出现中文乱码问题
- Linux下python matplotlib.pyplot在图像上显示中文的问题
- Linux下python matplotlib.pyplot在图像上显示中文的问题
- matplotlib pyplot 显示中文
- 三、Matplotlib系列---pyplot的中文显示
- Ubuntu 14.04 Matlab 2012a plot / title / xlabel / ylabel 无法修改字体及大小
- matplotlib.pyplot中文标题乱码
- Python 中,matplotlib绘图无法显示中文的问题
- Python 中,matplotlib绘图无法显示中文的问题
- Python中,matplotlib绘图无法显示中文的问题
- 【Python】Macbook Pro MacOS Sierra 无法加载 matplotlib.pyplot 解决办法
- 有感
- <<web>>3d 相册
- 【LeetCode】330. Patching Array
- js解析json数据
- LeetCode---Rectangle Area解题分析
- Python matplotlib pyplot中title() xlabel() ylabel()无法显示在中文(方框乱码)的解决办法
- select option ng-repeat多空白项
- Mysql存储过程优化——使用临时表代替游标
- 机械码补码,阶码的表示与范围思考总结
- Spark入门实战系列--7.Spark Streaming(下)--实时流计算Spark Streaming实战
- struts2 多文件上传
- Spark入门实战系列--8.Spark MLlib(上)--机器学习及SparkMLlib简介
- 《Redis设计与实现》阅读:Redis底层研究之简单动态字符串SDS
- cordova新建android工程