1、本文內容
python讀取文本數據曲線圖
2、轉載請注明出處:
https://blog.csdn.net/qq_41102371/article/details/125933558
import matplotlib.pyplot as plt
import numpy as np
if __name__=="__main__":
data_euler=np.loadtxt('./data_euler.txt')
data_midpoint=np.loadtxt('./data_midpoint.txt')
data_rk4=np.loadtxt('./data_rk4.txt')
x=data_euler[:,0]
x_max=max(data_euler[:,0])
x_axis=np.arange(0,x_max,0.0001)
y_gt=np.exp(x_axis)
y_euler=data_euler[:,2]
y_midpoint=data_midpoint[:,2]
y_rk4=data_rk4[:,2]
plt.plot(x_axis,y_gt,label="gt")
plt.plot(x,y_euler,label="euler")
plt.plot(x,y_midpoint,label="midpoint")
plt.plot(x,y_rk4,label="rk4")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
# 右側刻度
ax = plt.gca()
ax.tick_params(top=True,labeltop=True,labelright = True)
ax.grid()
plt.show()
數據為歐拉積分、中點積分、龍格-庫塔(Runge-Kutta)積分在[0,5]近似函數 y = e x y=e^x y=ex的結果, Δ t = 1 \Delta t=1 Δt=1,數據格式:x,gt,y_pred
數據生成代碼
數值積分方法:歐拉積分、中點積分和龍格-庫塔法積分 https://blog.csdn.net/qq_41102371/article/details/125935198
data_euler.txt
0 1 1
1 2.71828 2
2 7.38906 4
3 20.0855 8
4 54.5982 16
5 148.413 32
data_midpoint.txt
0 1 1
1 2.71828 2.5
2 7.38906 5.75
3 20.0855 13.125
4 54.5982 29.9375
5 148.413 68.2812
data_rk4.txt
0 1 1
1 2.71828 2.70833
2 7.38906 6.87674
3 20.0855 17.3832
4 54.5982 43.9276
5 148.413 111.003
numpy之函數exp() https://www.csdn.net/tags/MtTacg5sOTY3NDQtYmxvZwO0O0OO0O0O.html
python的Matplotlib怎麼在右邊也加上數字刻度? https://www.zhihu.com/question/295481997/answer/1552703058
python讀取txt文件並繪圖 https://wenku.baidu.com/view/ebff45b1de88d0d233d4b14e852458fb770b3868?aggId=08ffa01f346baf1ffc4ffe4733687e21af45ff0a
python繪制函數曲線 https://zhuanlan.zhihu.com/p/75588369
http://www.liuxiao.org/2018/05/%E6%AC%A7%E6%8B%89%E7%A7%AF%E5%88%86%E3%80%81%E4%B8%AD%E7%82%B9%E7%A7%AF%E5%88%86%E4%B8%8E%E9%BE%99%E6%A0%BC%EF%BC%8D%E5%BA%93%E5%A1%94%E7%A7%AF%E5%88%86/ 歐拉積分、中點積分與龍格-庫塔積分