python学习小记
python画的图表不能显示中文的时候,使用下面的代码可以解决这个问题:
import matplotlib matplotlib.use('qt4agg') #指定默认字体 matplotlib.rcParams['font.sans-serif'] = ['SimHei'] matplotlib.rcParams['font.family']='sans-serif'
画曲线的代码:
import numpy as np import matplotlib.pyplot as plt from pylab import * import matplotlib matplotlib.use('qt4agg') #指定默认字体 matplotlib.rcParams['font.sans-serif'] = ['SimHei'] matplotlib.rcParams['font.family']='sans-serif' # evenly sampled time at 200ms intervals t = np.arange(1,10, 0.001) # red dashes, blue squares and green triangles plt.plot(t, t**(-0.5), 'r--', t, t**(-1), 'b-..', t, t**(-2), 'g.') plt.title('区间[1,+∞]的反常积分与p的取值关系',fontsize=16) plt.text(2, 0.1, r'p=2,收敛',color='green',fontsize=13) plt.text(3.8, 0.3, r'p=1,发散',color='blue',fontsize=13) plt.text(4.5, 0.55, r'p=0.5,发散',color='red',fontsize=13) ylim(0, 1) xlim(1, 10) plt.show()