问题描述
我正在尝试使用 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
结尾缺少括号。