當前位置:首頁 » 編程語言 » python畫函數圖像

python畫函數圖像

發布時間: 2025-03-26 18:34:17

① 如何使用python的matplotlib畫正弦函數圖像

使用python的matplotlib畫正弦函數圖像,還要用到numpy庫,代碼如下9行所示:

import numpy as np;
from matplotlib import pyplot as plt;
fig = plt.figure();
ax2= fig.add_subplot(111);
x=np.arange(0,100)/10;
y=np.sin(x);
ax2.plot(x,y);
plt.savefig('sine.png');
plt.show();

② python畫正餘弦函數圖像

用python怎樣畫出如題所示的正餘弦函數圖像? 如此編寫代碼,使其中兩個軸、圖例、刻度,大小,LaTex公式等要素與原圖一致,需要用到的代碼如下,沒有縮進:


#-*-codeing:utf-8;-*-

from matplotlib import pyplot as plt

import numpy as np

a=np.linspace(0,360,980)

b=np.sin(a/180*np.pi)

c=np.cos(a/180*np.pi)

fig = plt.figure()

ax = fig.add_subplot(111)

ax.set_xlim([0, 360])

ax.plot(a,b,label=r"$y=sin( heta)$")

ax.plot(a,c,label=r"$y=cos( heta)$")

ax.grid(True)

ax.set_ylabel(r"$y$")

ax.set_xlabel(r"$ heta$")

plt.xticks(np.arange(0,360+1,45))

plt.title("Sine & Cosine Waves")

plt.legend()

plt.savefig("SinCosWaveDegFont.jpg")

plt.show()


代碼輸出的文件的圖

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:645
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:936
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:632
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:821
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:731
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1066
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:299
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:160
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:852
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:763