新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python繪制正弦函數(shù)圖像實例:打造你的Python畫圖技能!
準(zhǔn)備工作
1、安裝所需庫:matplotlib

2、導(dǎo)入所需庫:import matplotlib.pyplot as plt
繪制正弦函數(shù)圖像
1、創(chuàng)建x軸數(shù)據(jù):x = np.linspace(2 * np.pi, 2 * np.pi, 100)
2、計算y軸數(shù)據(jù):y = np.sin(x)
3、使用plt.plot()繪制圖像:plt.plot(x, y)
4、設(shè)置圖像標(biāo)題和坐標(biāo)軸標(biāo)簽:plt.title("正弦函數(shù)圖像"), plt.xlabel("x軸"), plt.ylabel("y軸")
5、顯示圖像:plt.show()
完整代碼
import numpy as np
import matplotlib.pyplot as plt
創(chuàng)建x軸數(shù)據(jù)
x = np.linspace(2 * np.pi, 2 * np.pi, 100)
計算y軸數(shù)據(jù)
y = np.sin(x)
繪制圖像
plt.plot(x, y)
設(shè)置圖像標(biāo)題和坐標(biāo)軸標(biāo)簽
plt.title("正弦函數(shù)圖像")
plt.xlabel("x軸")
plt.ylabel("y軸")
顯示圖像
plt.show()
運(yùn)行結(jié)果
運(yùn)行上述代碼,將生成一個正弦函數(shù)圖像。
當(dāng)前題目:Python繪制正弦函數(shù)圖像實例:打造你的Python畫圖技能!
瀏覽路徑:http://fisionsoft.com.cn/article/dpjhgdi.html


咨詢
建站咨詢
