我不断收到错误消息:AttributeError:“ NoneType”对象在python中没有属性“ set_facecolor”

时间:2020-05-02 15:17:08

标签: python-3.x

所以我定义了一个绘制图的函数:

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或其他内容带来相同的错误。我很困惑,有人可以帮我

0 个答案:

没有答案