【发布时间】:2017-06-27 19:13:48
【问题描述】:
我试图绘制 2 个图表的总和。当它是一个数字数组或一条直线时,我通过组合 y 值轻松地做到了这一点,但现在我使用相同的图表仅略微移动,并且 y 值由一个函数确定,所以我不知道该怎么做。这是我到目前为止所拥有的,而且我的一些尝试也是#'d。
import matplotlib.pyplot as plt
import numpy as np
h=6.626e-34
c= 3.0e+8
k= 1.38e-23
#wav is the wavelength
def planck(wav, T):
a= 2.0*h*c**2
b= (h*c)/(wav*k*T)
intensity = a/( (wav**5) * (np.exp(b)- 1.0) )
return intensity
wavelengths= np.arange(1e-9, 3e-6, 1e-9)
#wave=np.arange((1+500)*10**-9,3e-6,1e-9)
intensity6000= planck( wavelengths, 6000.)
#intensity6001=planck(wavelengths+(500*10**-9),6000)
#sum_of_values=intensity6000+
plt.plot(wavelengths*1e9, intensity6000, 'm-', label= '6000 K')
plt.plot(wavelengths*1e9+500, intensity6000, 'b', label='6000k shifted')
#plt.plot(wavelengths*1e9+wavelengths*1e9+500, intensity6000) this is wrong
it shifts it again doesnt show the total
#plt.plot(wavelengths*1e9+500,intensity6001) #plots a straight line at 0
plt.xlabel('Wavelength\n(nm)')
plt.ylabel('Intensity\n(W Sr^-1 m^-3)')
plt.title('Black Body Radiation')
plt.legend()
plt.show()
【问题讨论】:
-
您想将两个绘图函数相加吗?
-
是的。我不知道该怎么做。
标签: python python-3.x graphing