2017-12-18 163 views
0

我想繪製普朗克輻射方程,如下所示。當我使用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

一個計謀的計策

回答

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

+0

親愛的阿米特·辛格,這是我所期待的。非常感謝你的幫助。對此,我真的非常感激。 – mocs

+0

不客氣! –