I have this code to produce three plots. The code runs fine and produces all three plots as the way I wanted.
However, when I tried to save the plot, what I get is only the image of the last plot which is a plot for G0 and not the image of the plots showing one after another.
I tried using plt.show()
instead of using plt.savefig()
and plt.figure
, but that returns me a white(blank) image.
Can someone please help?
import numpy as np import matplotlib.pylab as plt
def planks_law(wave, T):
h = 6.626e-34
c = 3e8
k = 1.38e-23
bb = (2*h*c**2)/(wave**5)* (1/(np.exp((h*c)/(wave*k*T)-1)))
return bb
b0 = np.genfromtxt("filename.txt") plt.plot(b0[:, 0]*1e-10,b0[:, 1],label='B0 Data')
bb_b0 = planks_law(b0[:,0]*1e-10, 30000)
scale_bb = np.trapz(b0[:,1],b0[:,0]*1e-10) / np.trapz(bb_b0,b0[:,0]*1e-10)
bb_b0_scaled = bb_b0 * scale_bb
plt.plot(b0[:,0]*1e-10, bb_b0_scaled,label='B0 Theoretical')
plt.xlabel('Wavelength [m]') plt.ylabel('I(λ,T)')
plt.title('Blackbody Curve Fit to Known Spectra')
plt.legend(loc='upper right')
plt.savefig('filename.jpg')
plt.figure()
f0 = np.genfromtxt("filename.txt") plt.plot(f0[:, 0]*1e-10,f0[:, 1],label='F0 Data')
bb_f0 = planks_law(f0[:,0]*1e-10, 7200)
scale_bb = np.trapz(f0[:,1],f0[:,0]*1e-10) / np.trapz(bb_f0,f0[:,0]*1e-10)
bb_f0_scaled = bb_f0 * scale_bb
plt.plot(f0[:,0]*1e-10, bb_f0_scaled,label='F0 Theoretical')
plt.xlabel('Wavelength [m]') plt.ylabel('I(λ,T)')
plt.legend(loc='lower right')
plt.savefig('filename.jpg')
plt.figure()
g0 = np.genfromtxt("filename.txt") plt.plot(g0[:, 0]*1e-10,g0[:, 1],label='G0 Data')
bb_g0 = planks_law(g0[:,0]*1e-10, 6000)
scale_bb = np.trapz(g0[:,1],g0[:,0]*1e-10) / np.trapz(bb_g0,g0[:,0]*1e-10)
bb_g0_scaled = bb_g0 * scale_bb
plt.plot(g0[:,0]*1e-10, bb_g0_scaled,label='G0 Theoretical')
plt.xlabel('Wavelength [m]') plt.ylabel('I(λ,T)')
plt.legend(loc='lower right')
plt.figure()
plt.savefig('filename.jpg')