用python進行簡單的畫圖操作

來源:互聯網
上載者:User

標籤:網格   type   spi   port   numpy   ado   odi   coding   amp   

我用python的matplotlib模組進行簡單的畫圖操作,作為入門參考,下面直接上代碼:

#coding:utf-8import numpy as npimport matplotlib.pyplot as pltx=np.linspace(-np.pi,np.pi,512,endpoint=True)c=np.cos(x)s=np.sin(x)plt.figure(1)  #首先建立一張圖figure1plt.plot(x,c,color='red',linewidth='1.0',label='COS',linestyle='-',alpha=0.5)plt.plot(x,s,'b--',label="SIN")   #-表示畫線的類型,還可以用*畫線plt.title("COS & SIN")    #圖的名字#設定座標軸ax=plt.gca()      ax.spines["right"].set_color("none")   #設定座標軸的顏色ax.spines["top"].set_color("none")ax.spines["left"].set_position(("data",0))  #設定座標軸的位置ax.spines["bottom"].set_position(("data",0))ax.xaxis.set_ticks_position("bottom")   #x軸的資料顯示在x軸右側ax.yaxis.set_ticks_position("left")    #y軸的資料顯示在y軸左側plt.legend(loc="upper,left")  #顯示圖例#plt.axis([-1,1,-0.5,1])   #指定繪圖範圍,x從-1到1,y從-0.5到1plt.grid()     #顯示網格線plt.fill_between(x,np.abs(x)<0.5,c,c>0.7,color='green',alpha=0.5) #填充顏色plt.show()

作圖效果如下:

用python進行簡單的畫圖操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.