1、Matplotlib函數(shù)可以繪制圖形,使用plot函數(shù)繪制曲線。
2、需要將200個點的x坐標和Y坐標分別以序列的形式輸入plot函數(shù),然后調(diào)用show函數(shù)來顯示圖形。
import matplotlib.pyplot as plt #200個點的x坐標 x=range(-100,100) #生成y點的坐標 y=[i**2 for i in x ] #繪制一元二次曲線 plt.plot(x,y) #調(diào)用savefig將一元二次曲線保存為result.jpg plt.savefig('result.jpg') #如果直接寫成 plt.savefig('cos') 會生成cos.png plt.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()
到此這篇關(guān)于python一繪制元二次方程曲線的實例分析的文章就介紹到這了,更多相關(guān)python一元二次方程曲線的繪制內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!