Page view time visualizer - bar_plot - Number of bars 193 != 49

Hi all, i struggle for much too long on this task and dont want to copy a solution. The bar plot is printed out correctly (49 bars) but an error is returned:
test_bar_plots_number_of_bars: 193 != 49

my code is as follows:

# Import data (Make sure to parse dates. Consider setting index column to 'date'.)
df = pd.read_csv( "fcc-forum-pageviews.csv", index_col="date", parse_dates=True).sort_values('value')
# Clean data
df = df.iloc[(int(round((df.count() / 100 * 2,5)[0]))):(int(round(((df.count() / 100 * 97,5)[0])-1)))]
df = df.sort_index()

def draw_bar_plot():
    # Copy and modify data for monthly bar plot
    df_bar = df.groupby([df.index.year, df.index.month]).mean().fillna('')
    df_bar.index.names=['year', 'month']
    df_bar.reset_index(inplace=True)
    print(df_bar)
    # Draw bar plot
    fig = sns.barplot(data=df_bar, x="year", y="value", hue="month").get_figure()
    plt.xlabel('Years')
    plt.ylabel('Average Page Views')
    plt.legend(['January','February','March','April','May','June','July','August','September','October','November','December'])
    # Save image and return fig (don't change this part)
    # You can comment this line out if you don't need title
    fig.savefig('bar_plot.png')
    return fig

Can someone explain why this error appears? Thanks

sns.barplot doesn’t return Figure object (fig), but Axes object (ax).

Okay. I just had to add 1 line of code at the top of the function.

fig, ax = plt.subplots()

It seems like I have to invest more time in understanding the relation between Mathplotlib and Seaborn.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.