python一繪制元二次方程曲線的實例分析
1、Matplotlib函數可以繪制圖形,使用plot函數繪制曲線。
2、需要將200個點的x坐標和Y坐標分別以序列的形式輸入plot函數,然后調用show函數來顯示圖形。
實例import matplotlib.pyplot as plt#200個點的x坐標x=range(-100,100)#生成y點的坐標y=[i**2 for i in x ]#繪制一元二次曲線plt.plot(x,y)#調用savefig將一元二次曲線保存為result.jpgplt.savefig(’result.jpg’) #如果直接寫成 plt.savefig(’cos’) 會生成cos.pngplt.show()
實例擴展:
import matplotlib.pyplot as plt# 定義定義域[-10, 11]x_val = [i for i in range(-10,11)]# 求解應變量y_val = [5*x**2 for x in x_val]print(x_val)print(y_val)# 設置matplotlib作圖工具fig, ax = plt.subplots()ax.plot(x_val, y_val)ax.set(xlabel=’x(independentVariable)’, ylabel=’y(strain)’, title=’On the equation of a quadratic function’)ax.grid()# 保存圖片fig.savefig('test.png')# 展示圖片plt.show()
到此這篇關于python一繪制元二次方程曲線的實例分析的文章就介紹到這了,更多相關python一元二次方程曲線的繪制內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
