【发布时间】:2017-07-21 08:16:37
【问题描述】:
我想生成温度与功率的折线图,并编写了以下代码:
import numpy as np
import matplotlib.pyplot as plt
temps = np.arange(288, 314, 1)
sigma = 5.67e-8 #Stefan's constant, units = W m^-2 K^-4
T0 = 298 #ambient T, 25 degrees
emissivity = 0.96
A = (np.pi * 309)/80000 #total surface area of chameleon
def SB(T):
power = A * sigma * emissivity * (T**4 - T0**4)
return power
power = SB(temps)
plt.plot(temps, power)
plt.xlabel("Temperature (K)")
plt.ylabel("Power (W $m^{-2}$)")
plt.title("Net Power Radiated vs T")
plt.xlim(288, 314)
plt.ylim(0, 1.2)
plt.show()
轴正在显示,但我没有得到一条线,可能是因为该函数没有从 np.arange 中获取值吗?如果是这样,我将如何解决这个问题?任何帮助,将不胜感激! :D
雷切尔
【问题讨论】:
-
嗯,我复制并粘贴了你的代码,它正在绘制一条线。
-
您是否在交互式会话中编码?也许重新启动解释器。
-
@juanpa.arrivillaga 我在 Spyder 工作,但已经重新启动它并在另一个解释器中尝试过它现在说“RuntimeWarning:power遇到无效值”:/
-
等等。你在使用 Python 2 吗?
-
@juanpa.arrivillaga,是的,我认为是 Python 2.7,不知道两者之间的巨大差异哈哈
标签: python function numpy matplotlib