python数据处理_读取txt数据并绘图1、导⼊相关模块
import matplotlib.pyplot as plt  #绘图模块
from scipy import interpolate  #插值模块
import numpy as np  #数值计算模块
2、⽬标⽂件的定义与读取
file='F:\XZ_'#以⾼岭⽯波谱曲线为例
a = np.loadtxt(file)
x = a[:,0]#读取第⼀列所有数据
y = a[:,1]#读取第⼆列所有数据
3、函数拟合与插值
tck = interpolate.splrep(x,y)#拟合y与x
xx = np.linspace(min(x),max(x),200)#x插值
yy = interpolate.splev(xx,tck,der=0)
print(xx)
输出结果为:
[0.4002790.413222320.426165640.439108960.452052290.46499561
0.477938930.490882250.503825570.516768890.529712220.54265554
0.555598860.568542180.58148550.594428820.607372150.62031547
0.633258790.646202110.659145430.672088750.685032080.6979754
0.710918720.723862040.736805360.749748680.762692010.77563533
0.788578650.801521970.814465290.827408610.840351930.85329526
0.866238580.87918190.892125220.905068540.918011860.93095519
0.943898510.956841830.969785150.982728470.995671791.00861512
1.021558441.034501761.047445081.06038841.073331721.08627505
1.099218371.112161691.125105011.138048331.150991651.16393497
1.17687831.189821621.202764941.215708261.228651581.2415949
1.254538231.267481551.280424871.293368191.306311511.31925483
1.332198161.345141481.35808481.371028121.383971441.39691476
1.409858091.422801411.435744731.448688051.461631371.47457469
1.487518021.500461341.513404661.526347981.53929131.55223462
1.565177941.578121271.591064591.604007911.616951231.62989455
1.642837871.65578121.668724521.681667841.694611161.70755448
1.72049781.733441131.746384451.759327771.772271091.78521441
python怎么读取txt1.798157731.811101061.824044381.83698771.849931021.86287434
1.875817661.888760981.901704311.914647631.927590951.94053427
1.953477591.966420911.979364241.99230756
2.005250882.0181942
2.031137522.044080842.057024172.069967492.082910812.09585413
2.108797452.121740772.13468412.147627422.160570742.17351406
2.186457382.19940072.212344032.225287352.238230672.25117399
2.264117312.277060632.290003952.302947282.31589062.32883392
2.341777242.354720562.367663882.380607212.393550532.40649385
2.419437172.432380492.445323812.458267142.471210462.48415378
2.49709712.510040422.522983742.535927072.548870392.56181371
2.574757032.587700352.600643672.613586992.626530322.63947364
2.652416962.665360282.67830362.691246922.704190252.71713357
2.730076892.743020212.755963532.768906852.781850182.7947935
2.807736822.820680142.833623462.846566782.859510112.87245343
2.885396752.898340072.911283392.924226712.937170042.95011336
2.963056682.976]
4、绘图与显⽰
plt.plot(x,y,'-',xx,yy,color='red')#定义样式
plt.xlabel('Wavelength(µm)')#横坐标含义
plt.ylabel('Data Value')#纵坐标含义
plt.title('Kaolinite')```#图名(若附中⽂名称需导⼊并定义中⽂模块matplotlib.font_manager)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。