說明
1、Matplotlib函數可以繪制圖形,使用plot函數繪制曲線。
2、需要將200個點的x坐標和Y坐標分別以序列的形式輸入plot函數,然后調用show函數來顯示圖形。
實例
1
2
3
4
5
6
7
8
9
10
|
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.jpg plt.savefig( 'result.jpg' ) #如果直接寫成 plt.savefig('cos') 會生成cos.png plt.show() |
實例擴展:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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一元二次方程曲線的繪制內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://www.py.cn/jishu/jichu/31390.html