所以我定义了一个绘制图的函数:
def plot_by_date(df,countries,log,title,xtitle,ytitle):
fig=plt.figure(figsize=(20,10))
ax = fig.add_subplot()
ax.set_facecolor('whitesmoke')
plt.grid(True, linewidth=1, color='dimgrey',linestyle=':')
df=df.loc[countries].T
plt.plot(df) #linestyle="--"
plt.legend(df.columns,bbox_to_anchor=(1, 1), loc='upper left', borderaxespad=0.,frameon=False)
xmin=0;xmax=90;ymin=10;ymax=1000000
ax.set_xlim(xmin=xmin, xmax=xmax)
ax.set_ylim(ymin=ymin,ymax=ymax)
ax.set_ylabel(ytitle)
ax.set_xlabel(xtitle)
ax.set_title(title)
ax.set_xticklabels(df.T.columns, rotation = 70)
n = 3 # Keeps every 7th xlabel
[l.set_visible(False) for (i,l) in enumerate(ax.xaxis.get_ticklabels()) if i % n != 0]
if log==1:
ax.set_yscale('log')
return plt.show()
哪个运行都没有问题,但是当我尝试使用实际值来绘制它时:
df=active_grouped
countries=['Singapore','Korea, South','India','Pakistan','Iran','Australia','US','Spain','Italy','China','Germany']
log=1
title='Active Cases'
xtitle='Date'
ytitle='Active Cases (log scale)'
plot_by_date(df,countries,log,title,xtitle,ytitle)
我得到了错误的信息。删除setfacecolor属性会给xlim或ylim或其他内容带来相同的错误。我很困惑,有人可以帮我