Matplotlib中文显示的问题
2012-08-20 16:59
423 查看
#Matplotlib中文显示有问题,当然可以修改配置文件matplotlibrc ,不过较为麻烦.其实只要在代码中指定字体就可以了
#第一种方法:
# -*- coding: utf-8 -*-
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
#指定默认字体
mpl.rcParams['axes.unicode_minus'] =
False #解决保存图像是负号'-'显示为方块的问题
t = arange(-5*pi,
5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文')
plt.xlabel(u'X坐标')
plt.ylabel(u'Y坐标')
plt.show()
#第二种方法
# -*- coding: utf-8 -*-
from pylab import *
myfont = matplotlib.font_manager.FontProperties(fname='C:/Windows/Fonts/msyh.ttf')
mpl.rcParams['axes.unicode_minus'] =
False
t = arange(-5*pi,
5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文',fontproperties=myfont)
#指定字体
plt.xlabel(u'X坐标',fontproperties=myfont)
plt.ylabel(u'Y坐标',fontproperties=myfont)
plt.show()
#第一种方法:
# -*- coding: utf-8 -*-
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
#指定默认字体
mpl.rcParams['axes.unicode_minus'] =
False #解决保存图像是负号'-'显示为方块的问题
t = arange(-5*pi,
5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文')
plt.xlabel(u'X坐标')
plt.ylabel(u'Y坐标')
plt.show()
#第二种方法
# -*- coding: utf-8 -*-
from pylab import *
myfont = matplotlib.font_manager.FontProperties(fname='C:/Windows/Fonts/msyh.ttf')
mpl.rcParams['axes.unicode_minus'] =
False
t = arange(-5*pi,
5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文',fontproperties=myfont)
#指定字体
plt.xlabel(u'X坐标',fontproperties=myfont)
plt.ylabel(u'Y坐标',fontproperties=myfont)
plt.show()
相关文章推荐
- 解决python27 matplotlib 中文不显示问题
- python中matplotlib绘图中文显示问题
- 解决mac系统下Matplotlib 中文显示问题
- 解决python27 matplotlib 中文不显示问题
- matplotlib显示中文问题
- Python 中,matplotlib绘图无法显示中文的问题
- 基于Linux系统中python matplotlib画图的中文显示问题的解决方法
- 关于Mac系统下matplotlib中文显示方块问题
- matplotlib 中文显示问题的解决办法
- matplotlib画图中文显示问题
- Matplotlib及Seaborn中文显示问题
- python中matplotlib绘图中文显示问题
- matplotlib作图中文显示问题
- python中matplotlib绘图中文显示问题
- 解决matplotlib不能显示中文的问题(Ubuntu)
- 解决matplotlib绘制图片时中文无法正常显示的问题
- Linux下python matplotlib.pyplot在图像上显示中文的问题
- Matplotlib输出中文显示问题
- 解决python27 matplotlib 中文不显示问题
- matplotlib图例中文显示问题