import numpy from matplotlib import pyplot x=numpy.linspace(-3,3,50) y1=2*x+1 y2=x**2 pyplot.rcParams['font.sans-serif']=['simhei'] #顯示中文標簽 pyplot.rcParams['axes.unicode_minus']=False pyplot.figure(num='第一幅圖',figsize=(5,5)) k1,=pyplot.plot(x,y2,label='up') k2,=pyplot.plot(x,y1,color='red',linewidth=1,linestyle='--',label='down') pyplot.legend(handles=[k1,k2],labels=['拋物線','直線'],loc='best') #可以顯示圖例 #設定坐標軸范圍 pyplot.xlim((-1,2)) pyplot.ylim((-2,2)) #設定坐標軸標簽 pyplot.xlabel('i am x') pyplot.ylabel('i am y') #設定坐標軸刻度值 a=numpy.linspace(-1,2,5) pyplot.xticks(a) pyplot.yticks([-2,0,2],[r'$really\ bad$',r'$normal$',r'$really\ good$']) pyplot.show()

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/124178.html
標籤:Python
上一篇:陣列的拼接
