python一繪制元二次方程曲線(xiàn)的實(shí)例分析
1、Matplotlib函數(shù)可以繪制圖形,使用plot函數(shù)繪制曲線(xiàn)。
2、需要將200個(gè)點(diǎn)的x坐標(biāo)和Y坐標(biāo)分別以序列的形式輸入plot函數(shù),然后調(diào)用show函數(shù)來(lái)顯示圖形。
實(shí)例import matplotlib.pyplot as plt#200個(gè)點(diǎn)的x坐標(biāo)x=range(-100,100)#生成y點(diǎn)的坐標(biāo)y=[i**2 for i in x ]#繪制一元二次曲線(xiàn)plt.plot(x,y)#調(diào)用savefig將一元二次曲線(xiàn)保存為result.jpgplt.savefig(’result.jpg’) #如果直接寫(xiě)成 plt.savefig(’cos’) 會(huì)生成cos.pngplt.show()
實(shí)例擴(kuò)展:
import matplotlib.pyplot as plt# 定義定義域[-10, 11]x_val = [i for i in range(-10,11)]# 求解應(yīng)變量y_val = [5*x**2 for x in x_val]print(x_val)print(y_val)# 設(shè)置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一繪制元二次方程曲線(xiàn)的實(shí)例分析的文章就介紹到這了,更多相關(guān)python一元二次方程曲線(xiàn)的繪制內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息2. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法3. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說(shuō)明4. jsp網(wǎng)頁(yè)實(shí)現(xiàn)貪吃蛇小游戲5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向7. asp中response.write("中文")或者js中文亂碼問(wèn)題8. PHP設(shè)計(jì)模式中工廠模式深入詳解9. CSS hack用法案例詳解10. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過(guò)程(親測(cè)可用)
