標籤:問題: gre sim bsp square atp ams triangle text
python畫的圖表不能顯示中文的時候,使用下面的代碼可以解決這個問題:
import matplotlibmatplotlib.use(‘qt4agg‘)#指定預設字型matplotlib.rcParams[‘font.sans-serif‘] = [‘SimHei‘]matplotlib.rcParams[‘font.family‘]=‘sans-serif‘
畫曲線的代碼:
import numpy as npimport matplotlib.pyplot as pltfrom pylab import *import matplotlibmatplotlib.use(‘qt4agg‘)#指定預設字型matplotlib.rcParams[‘font.sans-serif‘] = [‘SimHei‘]matplotlib.rcParams[‘font.family‘]=‘sans-serif‘# evenly sampled time at 200ms intervalst = np.arange(1,10, 0.001)# red dashes, blue squares and green trianglesplt.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()
python學習小記