Plank辐射方程中有限范围的对数尺度图

时间:2017-12-18 02:02:51

标签: python numpy matplotlib

我试图绘制普朗克辐射方程,如下所示。当我使用Mathematica它很好,但是当我尝试使用Python时,我无法正确使用它。它基本上不会在低于1.0微米的波长下绘制。请参阅附件图片和代码。如果你能提供帮助,那将是非常值得注意的。提前谢谢。

import matplotlib.pyplot as plt
from matplotlib import pyplot
from matplotlib import pylab
import numpy as np

h = 6.626e-34
c = 2.9979e+8
k = 1.38e-23

def planck(wav, T):
    a = 2.0*3.14*h*c**2
    b = h*c/(wav*1e3*1e-9*k*T)
    intensity = a/ ( ((wav*1e3*1e-9)**5) * (np.exp(b) - 1.0) )*1e-6
    return intensity

wavelengths = np.logspace(1e-2, 1e2, 1e4, endpoint=False) 

intensity310 = planck(wavelengths, 310.)
intensity3000 = planck(wavelengths, 3000.)
intensity5800 = planck(wavelengths, 5800.)
intensity15000 = planck(wavelengths, 15000.)

plt.plot(wavelengths, intensity310, 'k-') # 5000K Black line
plt.plot(wavelengths, intensity3000, 'r-') # 5000K green line
plt.plot(wavelengths, intensity5800, 'y-') # 6000K blue line
plt.plot(wavelengths, intensity15000, 'b-') # 7000K Red line
pyplot.xscale('log')
pyplot.yscale('log')
pylab.xlim([1e-2,1e2])
pylab.ylim([1,1e10])
plt.show()

使用Python的情节 A plot using Python

使用Mathematica的情节

1 个答案:

答案 0 :(得分:0)

您使用np.logspace()时出错。如果您需要1e-21e2的值,则应分别使用参数-22调用该函数,即np.logspace(-2, 2, 1e4)。此外,如果要制作对数缩放图,可以使用pyplot.loglog()函数。无需导入pylab。请参阅以下代码:

import matplotlib.pyplot as plt
import numpy as np

h = 6.626e-34
c = 2.9979e+8
k = 1.38e-23

def planck(wav, T):
    a = 2.0*3.14*h*c**2
    b = h*c/(wav*1e3*1e-9*k*T)
    intensity = a/ ( ((wav*1e3*1e-9)**5) * (np.exp(b) - 1.0) )*1e-6
    return intensity

wavelengths = np.logspace(-2, 2, 1e4, endpoint=False) 

intensity310 = planck(wavelengths, 310.)
intensity3000 = planck(wavelengths, 3000.)
intensity5800 = planck(wavelengths, 5800.)
intensity15000 = planck(wavelengths, 15000.)

plt.loglog(wavelengths, intensity310, 'k-') # 5000K Black line
plt.loglog(wavelengths, intensity3000, 'r-') # 5000K green line
plt.loglog(wavelengths, intensity5800, 'y-') # 6000K blue line
plt.loglog(wavelengths, intensity15000, 'b-') # 7000K Red line
plt.xlim([1e-2,1e2])
plt.ylim([1,1e10])
plt.show()

我得到以下情节:

Plot