如何解决我正在尝试使用 pyplot.scatter() 但我收到无效的语法错误
我正在尝试使用 pyplot.scatter() 但出现以下错误:
plt.scatter(y=temperature_planet,x=t,s=2,color="red")
^
SyntaxError: invalid Syntax
您可以看到问题出在代码的最后一行。我不知道发生了什么
我的代码:
import numpy as np
import matplotlib.pyplot as plt
import time
import decimal
t = 0
temperature_planet = 200
temperature_atmosphere = 250
epsilon = decimal.Decimal(0.25)
dt = 60*10
heat_capacity = decimal.Decimal(1E5)
insolation = decimal.Decimal(1370)
sigma = decimal.Decimal(5.67E-8)
planet_radius = decimal.Decimal(6.4E6)
circle = decimal.Decimal(np.pi)*planet_radius**decimal.Decimal(2.0)
sphere = 4*decimal.Decimal(np.pi)*planet_radius**decimal.Decimal(2.0)
plt.scatter(y=temperature_planet,color="red")
plt.ion()
plt.xlabel("Time (S)")
plt.ylabel("Temperature (K)")
plt.legend(loc='upper left')
plt.show()
print(temperature_planet)
while True:
temperature_planet += dt*(circle*insolation + sphere* epsilon*sigma*
temperature_atmosphere**decimal.Decimal(4.0) -
sphere*sigma*temperature_planet**decimal.Decimal(4.0)/heat_capacity
t += dt
plt.scatter(y=temperature_planet,x=t)
plt.pause(0.005)
time.sleep(0.05)
解决方法
检查倒数第二行 sphere = 4*(np.pi*planet_radius**2.0
结尾缺少括号。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。