Matplotlib——數學函數圖像

import numpy as np
import matplotlib.pyplot as plt

# 準備x,y數據
x = np.linspace(-1, 1, 1000)
print(x)
y = 2 * (x ** 2)a

# 創建畫布
plt.figure(figsize=(20, 12), dpi=120)
# 繪製圖像
plt.plot(x, y)
# 添加網格
plt.grid(linestyle="--", alpha=0.5)
# 保存圖像
plt.savefig("數學函數.png")
# 顯示圖像
plt.show()

效果圖:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章