• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Plank辐射公式中对数范围图有限范围

python 来源:mocs 3次浏览

我想绘制普朗克辐射方程,如下所示。当我使用Mathematica时,绘图效果很好,但是当我尝试用Python来完成时,我无法正确理解它。它基本不会低于〜1.0微米波长。请参阅附件图片和代码。如果你能提供帮助,这将是非常可观的。先谢谢你。Plank辐射公式中对数范围图有限范围

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

一个计谋的计策

===========解决方案如下:

。在你的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


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)