我们正在寻找从温度5000K-10,000K绘制整个Plancks函数的图。
我已经尝试了各种方法来解决图形问题,但是看来我的格式设置或某种某种形式的结果导致数组值混合,我找不到解决方案
import math
import matplotlib.pyplot as plt
import numpy as np
#all constants
h=6.62e-34
c=2.998e8
k=1.3806503E-23
pi=np.pi
#equation
def planck(lamb1,T):
top=(2*h*c**2)/lamb1**5
bottom_hard=h*c/(lamb1*k*T)
Flux=top/((math.e**(bottom_hard)-1))
return Flux
# function inputs
lamb1=np.arange(0.1,10.1,.01)
Flux1=(lamb1*1e-6,5000)
Flux2=(lamb1*1e-6,6000)
Flux3=(lamb1*1e-6,7000)
Flux4=(lamb1*1e-6,8000)
Flux5=(lamb1*1e-6,9000)
Flux6=(lamb1*1e-6,10000)
#Actual plot
#data
wl = np.arange(10e-5, 10e-7,0.01*1e-6)
plt.plot(wl,Flux1)
plt.plot(wl,Flux2)
plt.plot(wl,Flux3)
plt.plot(wl,Flux4)
plt.plot(wl,Flux5)
plt.plot(wl,Flux6)
plt.xlabel("Wavelength(m)")
plt.ylabel("Flux(Vm)")
plt.title("Plancks Function Curve for Temp Ranges 5000K-10,000K")
plt.show()
我得到的错误是
ValueError: x and y must have same first dimension, but have shapes (1000,) and (2,)
我只需要获取实际的图形数据即可。完成后,我可以自己完成其余的编辑(希望如此!)
第一个问题在于您定义wl
的方式。
wl = np.arange(10e-5, 10e-7,0.01*1e-6)
意味着您创建的数组的值大于10e-5
,小于10e-7
。没有了!如果是,则定义
wl = np.arange(10e-7, 10e-5,1e-7)
您将有一个更好的起点。