Matplotlib中文显示问题——用例子说明问题
#-*- coding: utf-8 -*-
from pylab import *
t = arange(-4*pi, 4*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title('test')
plt.xlabel(u'\u2103',fontproperties='SimHei')
#在这里,u'\u2103'是摄氏度,前面的u代表unicode,而引号里的内容,是通过在网上查找“℃”这一个符号的unicode编码得到的。这里的“摄氏度”是中文,要显示的话需要在后面加上fontproperties属性即可,这里设置的字体为黑体。
plt.ylabel(u'幅度',fontproperties='SimHei')#也可以直接显示中文。
plt.show()
可以这样使用:ylabel('Rice('+r'$\mu\mathrm{mol}$'+'
'+'$ \mathrm{m}^{-2} \mathrm{s}^{-1}$'+')')。
中文与LaTex共同显示问题:
在坐标轴标题中同时显示中文以及带有上下标的各种数学单位,需要分两步:
1、根据上述显示中文的方法,先将中文标题加上;
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 10, 1000)
y = np.