Seaborn regplot: IndexError: too many indices for array

Viewed 110

I am trying to plot three graphs in one row. However, seaborn regplot is popping with error message: IndexError: too many indices for array Here is my Code:

slope, intercept, rv1, pv1, std_err = 
stats.linregress(ban_fc['TOTAL'],ban_fc['pm10'])
slope, intercept, rv2, pv2, std_err = 
stats.linregress(dma_fc['TOTAL'],dma_fc['pm10'])
slope, intercept, rv3, pv3, std_err = 
stats.linregress(prd_fc['TOTAL'],prd_fc['pm10'])

sns.set_style('whitegrid')
with sns.color_palette(n_colors=1):
    fig, axs = plt.subplots(1,3, figsize=(18,8),sharex=True, 
    sharey=True)
    sns.set(font_scale = 1.3)
    sns.regplot(x='TOTAL', y='pm10', 
    data=ban_fc,ax=axs[0,0],color='gray',ci=None, 
    label="r={0:.1f} p={1:.1f}".format(rv1, pv1)).legend(loc="best")
    sns.regplot(x='TOTAL', y='pm10', 
    data=dma_fc,ax=axs[0,1],color='gray',ci=None, 
    label="r={0:.1f} p={1:.1f}".format(rv2, pv2)).legend(loc="best")
    sns.regplot(x='TOTAL', y='pm10', 
    data=prd_fc,ax=axs[0,2],color='gray',ci=None, 
    label="r={0:.1f} p={1:.1f}".format(rv3, pv3)).legend(loc="best")

    for ax in axs.flat:
        ax.set(xlabel='Fire Count',ylim=(0,8500))

    for ax in axs.flat:
        ax.set(ylabel='PM$_1$$_0$('r'$\mu$g/m$^3$)',ylim=(0,200))
    fig.tight_layout()

When I increase the number of subplot rows to two the error disappeared, but the plot messed up with an extra blank subplot.

slope, intercept, rv1, pv1, std_err = 
stats.linregress(ban_fc['TOTAL'],ban_fc['pm10'])
slope, intercept, rv2, pv2, std_err = 
stats.linregress(dma_fc['TOTAL'],dma_fc['pm10'])
slope, intercept, rv3, pv3, std_err = 
stats.linregress(prd_fc['TOTAL'],prd_fc['pm10'])

sns.set_style('whitegrid')
with sns.color_palette(n_colors=1):
    fig, axs = plt.subplots(2,3, figsize=(18,8),sharex=True, 
    sharey=True)
    sns.set(font_scale = 1.3)
    sns.regplot(x='TOTAL', y='pm10', 
    data=ban_fc,ax=axs[0,0],color='gray',ci=None, 
    label="r={0:.1f} p={1:.1f}".format(rv1, pv1)).legend(loc="best")
    sns.regplot(x='TOTAL', y='pm10', 
    data=dma_fc,ax=axs[0,1],color='gray',ci=None, 
    label="r={0:.1f} p={1:.1f}".format(rv2, pv2)).legend(loc="best")
    sns.regplot(x='TOTAL', y='pm10', 
    data=prd_fc,ax=axs[0,2],color='gray',ci=None,
    label="r={0:.1f} p={1:.1f}".format(rv3, pv3)).legend(loc="best")

    for ax in axs.flat:
        ax.set(xlabel='Fire Count',ylim=(0,8500))

    for ax in axs.flat:
        ax.set(ylabel='PM$_1$$_0$('r'$\mu$g/m$^3$)',ylim=(0,200))
    fig.tight_layout()

Any help or suggestions are appreciated.

0 Answers
Related