Victor
Victor

Reputation: 17097

Matplotlib plt object getting shared across plots

I have 2 functions , one plots a time series line, other plots the autocrrelation.

def plotacorr(dfasst):
    # Plot autocorrelation
    plt.acorr(dfasst, maxlags=3)
    # Add labels to autocorrelation plot
    plt.title('Autocorrelation of Asset Balances with previous Months Balances')
    plt.xlabel('Lag in Months')
    plt.ylabel('Autocorrelation')

    # Display the autocorrelation plot
    #plt.show()
    plt.savefig('C:/acorr_assets.jpeg')

def plottrend(df_acctsmry2):
    fig, ax = plt.subplots()
    fmt = '${x:,.0f}'
    tick = mtick.StrMethodFormatter(fmt)
    ax.yaxis.set_major_formatter(tick) 

    df_acctsmry2.plot(x='REPORTING_DATE',ax=ax,figsize=(20,12))
    plt.xticks(fontsize=20)
    plt.yticks(fontsize=20)
    plt.xlabel('REPORTING_DATE', fontsize=18)
    #plt.show()
    plt.savefig('C:/output.jpeg')

I first call plottrend, followed by plotacorr But it seems that somehow the plt object is getting sharedbetween the 2 plots, so in the autocorrelation plot, I see the same result as plottrend.

Upvotes: 0

Views: 38

Answers (1)

Yuca
Yuca

Reputation: 6091

Uncomment the plt.show() on each function, that should do it (or call a plt.show() between the call to functions).

Upvotes: 1

Related Questions