时间:2021-05-22
我们经常需要导入数据,按列提取 XY作图
方法一、
filename='/home/res/user/csluo/test.txt' #将文件名赋值为变量 X,Y,Z=[ ],[ ],[ ] #给三个空列表 with open(filename, 'r') as f: #打开文档 lines=f.readlines() #按行读取数据 for i in lines: value=[ float(s) for s in line.split( ) ] #将 行数据 以空格分开,并以浮点型赋给value X=append(value[0]) #将value 的第一个数值 添加到 列表X Y=append(value[1]) Z=append(value[2])方法二、
a = numpy.loadtxt('a.txt') a[:,0]方法三、
>>> import pandas as pd>>> data = pd.read_csv("aaa.csv")附录:IRAS16293 的数据 绘图代码
import matplotlibimport matplotlib.pyplot as pltimport numpy as np ########################################################################################################################################################### ######## 1################################################################## #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A1_145122-145580.txt'X10,Y10= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] #以空格分开 行 并输出 浮点数 X10.append(value[0]) Y10.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A1/xclass_spectrum_output.dat'X11,Y11 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X11.append(value[0]) Y11.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A1/xclass_spectrum_output.dat'X12,Y12 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X12.append(value[0]) Y12.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_A/A1/xclass_spectrum_output.dat'X13,Y13 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X13.append(value[0]) Y13.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_A/A1/xclass_spectrum_output.dat'X14,Y14 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X14.append(value[0]) Y14.append(value[1]) ################################################### data_b filename = '/home/luoluo/Documents/python_scripts/Bdata_cut/B1_145122-145580.txt'X15,Y15= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X15.append(value[0]) Y15.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_B/B1/xclass_spectrum_output.dat'X16,Y16 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X16.append(value[0]) Y16.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_B/B1/xclass_spectrum_output.dat'X17,Y17 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X17.append(value[0]) Y17.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_B/B1/xclass_spectrum_output.dat'X18,Y18 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X18.append(value[0]) Y18.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_B/B1/xclass_spectrum_output.dat'X19,Y19 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X19.append(value[0]) Y19.append(value[1]) ################################################################### #2 plot plt.figure(1)plt.subplot(211)plt.axis([145122,145580, -1, 15]) new_ticks = np.linspace(145122,145580,10)plt.xticks(new_ticks) matplotlib.rcParams['xtick.direction'] = 'in'matplotlib.rcParams['ytick.direction'] = 'in'plt.plot(X10,Y10,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X11,Y11,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X12,Y12,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X13,Y13,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X14,Y14,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')#plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(145535,13,'IRAS16293A') #plt.show()#plt.savefig('8.png') plt.subplot(212)plt.axis([145122,145580, -1, 15]) new_ticks = np.linspace(145122,145580,10)plt.xticks(new_ticks) plt.plot(X15,Y15,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X16,Y16,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X17,Y17,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X18,Y18,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X19,Y19,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(145535,13,'IRAS16293B') plt.plot([145263,145263],[1,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("C2H5OH", xy = (145263,1), xytext = (145280,9),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.show() ########################################################################################################################################################### ######## 2################################################################## #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A2_145580-146050.txt'X20,Y20= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X20.append(value[0]) Y20.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A2/xclass_spectrum_output.dat'X21,Y21 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X21.append(value[0]) Y21.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A2/xclass_spectrum_output.dat'X22,Y22 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X22.append(value[0]) Y22.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_A/A2/xclass_spectrum_output.dat'X23,Y23 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X23.append(value[0]) Y23.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_A/A2/xclass_spectrum_output.dat'X24,Y24 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X24.append(value[0]) Y24.append(value[1]) ################################################### data_b filename = '/home/luoluo/Documents/python_scripts/Bdata_cut/B2.txt'X25,Y25= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X25.append(value[0]) Y25.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_B/B2/xclass_spectrum_output.dat'X26,Y26 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X26.append(value[0]) Y26.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_B/B2/xclass_spectrum_output.dat'X27,Y27 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X27.append(value[0]) Y27.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_B/B2/xclass_spectrum_output.dat'X28,Y28 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X28.append(value[0]) Y28.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_B/B2/xclass_spectrum_output.dat'X29,Y29 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X29.append(value[0]) Y29.append(value[1]) ################################################################### #2 plot plt.figure(2)plt.subplot(211)plt.axis([145580,146050, -1, 15]) new_ticks = np.linspace(145580,146050,10)plt.xticks(new_ticks) matplotlib.rcParams['xtick.direction'] = 'in'matplotlib.rcParams['ytick.direction'] = 'in'plt.plot(X20,Y20,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X21,Y21,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X22,Y22,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X23,Y23,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X24,Y24,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')#plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(146000,13,'IRAS16293A') plt.plot([145618.5,145618.5],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (145618,7), xytext = (145650,11),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([146020,146020],[7,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146020,6), xytext = (146005,10),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) #plt.show()#plt.savefig('8.png') plt.subplot(212)plt.axis([145580,146050, -1, 15]) new_ticks = np.linspace(145580,146050,10)plt.xticks(new_ticks) plt.plot(X25,Y25,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X26,Y26,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X27,Y27,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X28,Y28,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X29,Y29,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(146000,13,'IRAS16293B') plt.plot([145618.5,145618.5],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (145618,7), xytext = (145650,11),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([146020,146020],[7,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146020,6), xytext = (145990,10),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.show() ########################################################################################################################################################### ######## 3################################################################## #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A3.txt'X30,Y30= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X30.append(value[0]) Y30.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A3/xclass_spectrum_output.dat'X31,Y31 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X31.append(value[0]) Y31.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A3/xclass_spectrum_output.dat'X32,Y32 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X32.append(value[0]) Y32.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_A/A3/xclass_spectrum_output.dat'X33,Y33 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X33.append(value[0]) Y33.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_A/A3/xclass_spectrum_output.dat'X34,Y34 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X34.append(value[0]) Y34.append(value[1]) ################################################### data_b filename = '/home/luoluo/Documents/python_scripts/Bdata_cut/B3_146050-146507.txt'X35,Y35= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X35.append(value[0]) Y35.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_B/B3/xclass_spectrum_output.dat'X36,Y36 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X36.append(value[0]) Y36.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_B/B3/xclass_spectrum_output.dat'X37,Y37 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X37.append(value[0]) Y37.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_B/B3/xclass_spectrum_output.dat'X38,Y38 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X38.append(value[0]) Y38.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_B/B3/xclass_spectrum_output.dat'X39,Y39 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X39.append(value[0]) Y39.append(value[1]) ################################################################### #2 plot plt.figure(3)plt.subplot(211)plt.axis([146050,146507, -1, 15]) new_ticks = np.linspace(146050,146507,10)plt.xticks(new_ticks) matplotlib.rcParams['xtick.direction'] = 'in'matplotlib.rcParams['ytick.direction'] = 'in'plt.plot(X30,Y30,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X31,Y31,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X32,Y32,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X33,Y33,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X34,Y34,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')#plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(146465,13,'IRAS16293A') plt.plot([146172,146172],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146172,7), xytext = (146190,11),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([146232,146232],[3,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146232,10), xytext = (146210,5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([146343,146343],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146343,7), xytext = (146320,12),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([146355,146355],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146355,6), xytext = (146380,7),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) #plt.show()#plt.savefig('8.png') plt.subplot(212)plt.axis([146050,146507, -1, 15]) new_ticks = np.linspace(146050,146507,10)plt.xticks(new_ticks) plt.plot(X35,Y35,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X36,Y36,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X37,Y37,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X38,Y38,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X39,Y39,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(146465,13,'IRAS16293B') plt.plot([146343,146343],[5.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146343,7), xytext = (146320,12),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([146355,146355],[5.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3OCHO v18=1", xy = (146355,6), xytext = (146380,7),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) #plt.plot([157324,157324],[2.5,15], color ='grey', linewidth=1, linestyle="--")#plt.annotate("CH3COCH3", xy = (157324,3), xytext = (157347,4.5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.show() ########################################################################################################################################################### ######## 4################################################################## #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A4'X40,Y40= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X40.append(value[0]) Y40.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A4/xclass_spectrum_output.dat'X41,Y41 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X41.append(value[0]) Y41.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A4/xclass_spectrum_output.dat'X42,Y42 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X42.append(value[0]) Y42.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_A/A4/xclass_spectrum_output.dat'X43,Y43 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X43.append(value[0]) Y43.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_A/A4/xclass_spectrum_output.dat'X44,Y44 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X44.append(value[0]) Y44.append(value[1]) ################################################### data_b filename = '/home/luoluo/Documents/python_scripts/Bdata_cut/B4_146507-146976.txt'X45,Y45= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X45.append(value[0]) Y45.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_B/B4/xclass_spectrum_output.dat'X46,Y46 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X46.append(value[0]) Y46.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_B/B4/xclass_spectrum_output.dat'X47,Y47 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X47.append(value[0]) Y47.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_B/B4/xclass_spectrum_output.dat'X48,Y48 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X48.append(value[0]) Y48.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_B/B4/xclass_spectrum_output.dat'X49,Y49 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X49.append(value[0]) Y49.append(value[1]) ################################################################### #2 plot plt.figure(4)plt.subplot(211)plt.axis([146507,146976, -1, 15]) new_ticks = np.linspace(146507,146976,10)plt.xticks(new_ticks) matplotlib.rcParams['xtick.direction'] = 'in'matplotlib.rcParams['ytick.direction'] = 'in'plt.plot(X40,Y40,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X41,Y41,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X42,Y42,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X43,Y43,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X44,Y44,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')#plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(146930,13,'IRAS16293A') #plt.plot([157323,157323],[2.5,15], color ='grey', linewidth=1, linestyle="--")#plt.annotate("CH3COCH3", xy = (157323,3), xytext = (157345,4.5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) #plt.show()#plt.savefig('8.png') plt.subplot(212)plt.axis([146507,146976, -1, 15]) new_ticks = np.linspace(146507,146976,10)plt.xticks(new_ticks) plt.plot(X45,Y45,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X46,Y46,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X47,Y47,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X48,Y48,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X49,Y49,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(146930,13,'IRAS16293B') #plt.plot([157324,157324],[2.5,15], color ='grey', linewidth=1, linestyle="--")#plt.annotate("CH3COCH3", xy = (157324,3), xytext = (157347,4.5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.show() ########################################################################################################################################################### ######## 5################################################################## #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A5_156840-157303.txt'X50,Y50= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X50.append(value[0]) Y50.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A5/xclass_spectrum_output.dat'X51,Y51 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X51.append(value[0]) Y51.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A5/xclass_spectrum_output.dat'X52,Y52 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X52.append(value[0]) Y52.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_A/A5/xclass_spectrum_output.dat'X53,Y53 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X53.append(value[0]) Y53.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_A/A5/xclass_spectrum_output.dat'X54,Y54 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X54.append(value[0]) Y54.append(value[1]) ################################################### data_b filename = '/home/luoluo/Documents/python_scripts/Bdata_cut/B5_156840-157303.txt'X55,Y55= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X55.append(value[0]) Y55.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_B/B5/xclass_spectrum_output.dat'X56,Y56 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X56.append(value[0]) Y56.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_B/B5/xclass_spectrum_output.dat'X57,Y57 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X57.append(value[0]) Y57.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_B/B5/xclass_spectrum_output.dat'X58,Y58 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X58.append(value[0]) Y58.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_B/B5/xclass_spectrum_output.dat'X59,Y59 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X59.append(value[0]) Y59.append(value[1]) ################################################################### #2 plot plt.figure(5)plt.subplot(211)plt.axis([156840, 157303, -1, 15]) new_ticks = np.linspace(156840,157303,10)plt.xticks(new_ticks) matplotlib.rcParams['xtick.direction'] = 'in'matplotlib.rcParams['ytick.direction'] = 'in'plt.plot(X50,Y50,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X51,Y51,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X52,Y52,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X53,Y53,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X54,Y54,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')#plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(157256,13,'IRAS16293A') #plt.show()#plt.savefig('8.png') plt.subplot(212)plt.axis([156820,157303, -1, 15]) new_ticks = np.linspace(156820,157303,10)plt.xticks(new_ticks) plt.plot(X55,Y55,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X56,Y56,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X57,Y57,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X58,Y58,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X59,Y59,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(157255,13,'IRAS16293B') #plt.plot([157324,157324],[2.5,15], color ='grey', linewidth=1, linestyle="--")#plt.annotate("CH3COCH3", xy = (157324,3), xytext = (157347,4.5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.show() ########################################################################################################################################################### ######## 6################################################################## #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A6_157303-157820.txt'X60,Y60= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X60.append(value[0]) Y60.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A6/xclass_spectrum_output.dat'X61,Y61 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X61.append(value[0]) Y61.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A6/xclass_spectrum_output.dat'X62,Y62 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X62.append(value[0]) Y62.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_A/A6/xclass_spectrum_output.dat'X63,Y63 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X63.append(value[0]) Y63.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_A/A6/xclass_spectrum_output.dat'X64,Y64 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X64.append(value[0]) Y64.append(value[1]) ################################################### data_b filename = '/home/luoluo/Documents/python_scripts/Bdata_cut/B6_157303-157820.txt'X65,Y65= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X65.append(value[0]) Y65.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_B/B6/xclass_spectrum_output.dat'X66,Y66 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X66.append(value[0]) Y66.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_B/B6/xclass_spectrum_output.dat'X67,Y67 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X67.append(value[0]) Y67.append(value[1]) #ch3ocho_v18=1filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v18=1_B/B6/xclass_spectrum_output.dat'X68,Y68 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X68.append(value[0]) Y68.append(value[1]) #ch3ocho_v=0filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3OCHO_v=0_B/B6/xclass_spectrum_output.dat'X69,Y69 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X69.append(value[0]) Y69.append(value[1]) ################################################################### #2 plot plt.figure(6)plt.subplot(211)plt.axis([157303, 157820, -1, 15]) new_ticks = np.linspace(157303, 157820,10)plt.xticks(new_ticks) matplotlib.rcParams['xtick.direction'] = 'in'matplotlib.rcParams['ytick.direction'] = 'in'plt.plot(X60,Y60,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X61,Y61,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X62,Y62,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X63,Y63,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X64,Y64,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')#plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(157765,13,'IRAS16293A') plt.plot([157323,157323],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3COCH3", xy = (157323,3), xytext = (157345,4.5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) #plt.show()#plt.savefig('8.png') plt.subplot(212)plt.axis([157303, 157820, -1, 15]) new_ticks = np.linspace(157303, 157820,10)plt.xticks(new_ticks) plt.plot(X65,Y65,color='k',lw=1.0,ls='-',label='DATA') plt.plot(X66,Y66,color='r',lw=1.0,ls='-',label='C2H5OH')plt.plot(X67,Y67,color='g',lw=1.0,ls='-',label='CH3COCH3')plt.plot(X68,Y68,color='cyan',lw=1.0,ls='-',label='CH3OCHO v18=1')plt.plot(X69,Y69,color='b',lw=1.0,ls='-',label='CH3OCHO v=0')plt.legend(loc='upper left')plt.xlabel('Freq(MHZ)')plt.ylabel('T(K)')plt.text(157765,13,'IRAS16293B') plt.plot([157324,157324],[2.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("CH3COCH3", xy = (157324,3), xytext = (157347,4.5),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.plot([157505.5,157505.5],[5.5,15], color ='grey', linewidth=1, linestyle="--")plt.annotate("C2H5OH", xy = (157505,6), xytext = (157450,11),arrowprops = dict(facecolor = "y", headlength=10, headwidth =3, width =0.1)) plt.show() ############################################################################################################################################################################################################### 7############################################################################################### #data_afilename = '/home/luoluo/Documents/python_scripts/Adata_cut/A7_157820-158228.txt'X70,Y70= [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X70.append(value[0]) Y70.append(value[1]) #c2h5ohfilename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__C2H5OH_A/A7/xclass_spectrum_output.dat'X71,Y71 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X71.append(value[0]) Y71.append(value[1]) #ch3coch3filename = '/home/luoluo/Documents/python_scripts/job__XCLASS/job__CH3COCH3_A/A7/xclass_spectrum_output.dat'X72,Y72 = [],[]with open(filename, 'r') as f: lines = f.readlines() for line in lines: value = [float(s) for s in line.split()] X声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了PHP将Excel导入数据库及数据库数据导出至Excel的方法。分享给大家供大家参考。具体实现方法如下:一.导入导入需要使用能读取Excel的组件
本文实例讲述了Python使用import导入本地脚本及导入模块的技巧。分享给大家供大家参考,具体如下:导入本地脚本import如果你要导入的Python脚本与
getpass模块的使用:在python中实现密码密文需要导入getpass模块,在python中要使用内置模块的话,需要使用import进行导入,比如impo
python不能像C++一样直接定义一个static变量或者通过extern来导入别的库的变量而实现数据共享,但是python的思想是通过模块化来解决这个问题,
本文所示代码主要是通过Python+matplotlib实现作图,并且在图中添加表格的功能,具体如下。代码importmatplotlib.pyplotaspl