I am currently trying to plot a function which describes linear perturbation growth in cosmology for different world models. I would like to be able to have all the curves on the same set of axes, but am struggling with setting it up.
My aim is to plot this function D, with respect to z, but have multiple plots with varying density parameters ($\Omega$).
I have managed two solutions but both aren't working perfectly, the first is very inefficient (adding new functions for each set of parameters):
z = np.arange(0.0,10,0.1) #density parameters MOm = 1.0 MOv = 0.0 COm = 0.3 COv = 0.7 H0 = 70 def Mf(z): A = (5/2)*MOm*(H0**2) H = H0 * np.sqrt( MOm*((1+z)**3) + MOv ) return A * ((1+z)/(H**3)) def MF(z): res = np.zeros_like(z) for i,val in enumerate(z): y,err = integrate.quad(Mf,val,np.inf) res[i] = y return res def MD(z): return (H0 * np.sqrt( MOm*((1+z)**3) + MOv )) * MF(z) def Cf(z): A = (5/2)*COm*(H0**2) H = H0 * np.sqrt( COm*((1+z)**3) + COv ) return A * ((1+z)/(H**3)) def CF(z): res = np.zeros_like(z) for i,val in enumerate(z): y,err = integrate.quad(Cf,val,np.inf) res[i] = y return res def CD(z): return (H0 * np.sqrt( COm*((1+z)**3) + COv )) * CF(z) plt.plot(z,MD(z),label="Matter Dominated") plt.plot(z,CD(z),label="Current Epoch") So I tried to make it simpler with a for loop, but have been unable to work out how to add labels to each plot inside the loop:
Om = (1.0,0.3) Ov = (0.0,0.7) for param1,param2 in zip(Om,Ov): def f(z): A = (5/2)*param1*(H0**2) H = H0 * np.sqrt( param1*((1+z)**3) + param2 ) return A * ((1+z)/(H**3)) def F(z): res = np.zeros_like(z) for i,val in enumerate(z): y,err = integrate.quad(f,val,np.inf) res[i] = y return res def D(z): return (H0 * np.sqrt( param1*((1+z)**3) + param2 )) * F(z) plt.plot(z,D(z)) Could someone please help explain an efficient method of doing so? Or how to add labels to plots on the fly with a for loop. Any help would be greatly appreciated.

