Tell us what’s happening:
Whenever I try to order Months in chronological order for the barplot (order=[‘Jan’,‘Feb’,‘Mar’,‘Apr’,‘May’,‘Jun’,‘Jul’,‘Aug’,‘Sep’,‘Oct’,‘Nov’,‘Dec’]), it stops displaying bars and the legend still isn’t in the correct order. I tried solving this with sorting data beforehand but I couldn’t find a solution.
What’s weird is that it works pretty well for the following boxplot.
Your code so far
def draw_bar_plot():
# Copy and modify data for monthly bar plot
df_bar = df.copy()
df_bar.reset_index(inplace=True)
df_bar['Years'] = [d.year for d in df_bar.date]
df_bar['Months'] = [d.strftime('%b') for d in df_bar.date]
df_bar = df_bar.drop('date', axis=1)
# Draw bar plot
fig = plt.figure(figsize=(15,13))
ax = sns.barplot(data=df_bar, x='Years', y='value', palette=sns.color_palette('tab10',12), hue='Months', errorbar=('ci', 0))
ax.set_xlabel('Years')
ax.set_ylabel('Average Page Views')
#plt.show()
# Save image and return fig (don't change this part)
fig.savefig('bar_plot.png')
return fig
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Data Analysis with Python Projects - Page View Time Series Visualizer
Link to the challenge: