用相似的代码绘制图形 [英] Plotting graphs with similar codes

查看:38
本文介绍了用相似的代码绘制图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个代码绘制了我的图表:

I plotted my graph with this code:

from numpy import*
from matplotlib.pyplot import*
h=6.626*10**(-34)
c=3*10**8
k=1.38*10**(-23)
t=6000
l=[]
s=arange(100,2000,1)
def fun(x,t):
    e=(2*pi*h*c**2)/(x**5*(exp((h*c)/(x*k*t))-1))
    return e
for x in arange(100*10**(-9),2000*10**(-9),1*10**(-9)):
    r=fun(x,t)
    l.append(r)
plot(s,l)
show()

感谢 RandomGuy,他提供了一个非常紧凑的代码:

And courtesy to RandomGuy, he gave a much compact code:

from numpy import*
from matplotlib.pyplot import*
h=6.626*10**(-34)
c=3*10**8
T=6000
k=1.38*10**(-23)
l=linspace(100*10**(-9),2001*10**(-9),100)
E=(2*pi*h*c**2)/((l**5)*exp(h*c/(l*k*T)-1))
plot(l,E)
show

但问题是,我得到了不同的峰值最大值.在第一个中,它接近1,但是在第二个中,它大于2.5.是什么让这些代码与众不同?

But the problem is, I am getting different maximas for the peaks. In the first one, it is near 1, but for the second, it is more than 2.5. What makes these codes different?

推荐答案

区别在于指数的参数.

在第二个函数中, -1 exp 的参数中,而第一个函数则不是这种情况.

In the second function, -1 is in the argument of exp which is not the case for the first one.

这篇关于用相似的代码绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆