问题描述
我正在尝试生成一个具有三个动态元素的图例,并且出现此错误,我无法在线找到解决方案,而我尝试过的方法无效。图例中的变量为“ slp”,然后来自以下变量“ df”的“经度”和“纬度”:
slp
Out[40]: -0.01
df.head()
Out[39]:
index time windfarm_name longitude latitude wind_speed power
0 0 1991 Mihai Viteazu 28.62354 44.661127 6.473449 36.751247
1 1 1992 Mihai Viteazu 28.62354 44.661127 6.812166 41.154665
2 2 1993 Mihai Viteazu 28.62354 44.661127 6.986128 43.005901
3 3 1994 Mihai Viteazu 28.62354 44.661127 6.437906 36.975193
4 4 1995 Mihai Viteazu 28.62354 44.661127 6.610920 38.629562
错误消息是- TypeError:图例仅接受两个非关键字参数
我的代码看起来像这样,问题出在plt.legend所在的行上。感谢您提出的建议,我可以尝试创建具有三个动态元素的图例!
#Wind Farm Trend Test Mean Monthly Wind Speed by Year
wf = ncData.groupby([pd.Grouper(key='time',freq='1Y'),pd.Grouper(key='windfarm_name')]).mean() #
wf = wf.reset_index() #reset index to get 4 cols vs 2 with "time" column
#yrmo = wf['time'].dt.strftime('%Y-%m') #seperate out the year month from "time"
yrmo = wf['time'].dt.strftime('%Y') #seperate out the year month from "time"
wff = wf.assign(time=yrmo) #asssign year to dg df
windfarms = wff['windfarm_name']
lons = wff['longitude']
lats = wff['latitude']
reswf = []
wfspd= pd.DataFrame()
windspeed = wff['wind_speed']
mylist = wff.windfarm_name.unique() #unique windfarm names or total windfarms
for k in range(0,len(mylist)):
df = wff[(wff['windfarm_name'] == mylist[k])].reset_index()
#result2 = mk.seasonal_test(df.wind_speed)#seasonal mann-kendall test for monthly/seasonal data
result2 = mk.original_test(df.wind_speed)#mann-kendall test
trnd = result2.trend
print('----Mean Wind Speeds---->' + mylist[k],trnd)
slp = round(result2.slope,2)
print(result2.slope) #MOS wind speed in m/s
if trnd == 'decreasing':
tseq = list(range(0,len(df)))
df.plot(x ='time',y='wind_speed',kind = 'line')
#plt.title(mylist[k])
plt.title('1991-2019 Decreasing Trend - {}'.format(mylist[k]))
plt.ylabel('m / s')
plt.xlabel('Date')
plt.legend(['Chinook MOS Wind Speed & Trend Slope {} m/s'.format(slp)],['Longitude'.format(df.longitude.iloc[0])],['Latitude'.format(df.latitude.iloc[0])])
z = np.polyfit(tseq,df.wind_speed,1)
p = np.poly1d(z)
plt.plot(tseq,p(tseq),"r--")
plt.show()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)