如何解决如何在python中连续绘制3个图
我正在使用 for 循环遍历多个文件并在 Python 中绘制它的 x-y 值。但是,我的代码在新行中绘制每个图。我有兴趣在移动到下一行之前在一行中绘制 3 个图。任何建议都会有所帮助。
import csv
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import curve_fit
from scipy import asarray as ar,exp
import glob
import os
from lmfit import Model
path=r'E:\Users\ConfocalUser\Documents\GitHub\qudi\NV_Points'
##create a function to iterate over a folder and###########################################
###########################################################################################
def getcsvfile():
xData=[]
yData=[]
files=glob.glob(os.path.join(path,'*.csv'))
for file in files:
with open(file,"r") as f_in:
reader=csv.reader(f_in)
next(reader)
for line in reader:
try:
float_1,float_2=float(line[0]),float(line[1])
xData.append(float_1)
yData.append(float_2)
# print('x-values for file',file,xData)
# print('y-values for file',yData)
except ValueError:
continue
################################plot the xData and yData for each of the files within the folder#############
#############################################################################################################
# plt.plot(xData,yData,'bo',label='experimental_data')
# plt.xlabel('x,y,z distribution')
# plt.ylabel('PL intensity')
# basename = os.path.basename(file)
# plt.title(basename)
# plt.show()
######################### define the function you want to fit (Gaussian-fit)################################
############################################################################################################
xData=np.array(xData)
yData=np.array(yData)
mean=sum(xData*yData)/sum(yData)
sigma=np.sqrt(sum(yData*(xData-mean)**2)/sum(yData))
def Gauss(x,I0,x0,sigma,Background):
return I0*exp((-(x-x0)**2)/(2*sigma**2))+Background
##################################### Plot the fit for each of the files ###################################
############################################################################################################
mod=Model(Gauss)
result=mod.fit(yData,x=xData,I0=1,x0=mean,sigma=sigma,Background=1)
result.plot()
plt.grid()
plt.xlabel('x,z distribution')
plt.ylabel('PL intensity')
basename=os.path.basename(file)
plt.title(basename)
print('The fit statistics for',basename)
print(result.fit_report())#min_correl=0.25))
xData=[]
yData=[]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。