Page View Time Series Visualizer - Box Plot

Tell us what’s happening:
I was plotting two boxplot side by side , by it getting plotted only one plot. Can any help in this issue.

Your code so far
def draw_box_plot():
# Prepare data for box plots (this part is done!)
df_box = df.copy()
df_box.reset_index(inplace=True)
df_box[‘year’] = [d.year for d in df_box.date]
df_box[‘month’] = [d.strftime(’%b’) for d in df_box.date]

# Draw box plots (using Seaborn)
fig , (ax1, ax2) = plt.subplots(1,2)

ax1 = sns.boxplot(x='year',y='value',data=df_box)
ax1.set_xlabel('Year')
ax1.set_ylabel('Page Views')
ax1.set_title('Year-Wise Box Plot(Trends)')


ax2 = sns.boxplot(x='month', y='value', data=df_box)
ax2.set_xlabel('Month')
ax2.set_ylabel('Page Views')
ax2.set_title('Month-wise Box Plot(Seasonality)')


# Save image and return fig (don't change this part)
fig.savefig('box_plot.png')
return fig

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36.

Challenge: Page View Time Series Visualizer

Link to the challenge:
https://www.freecodecamp.org/learn/data-analysis-with-python/data-analysis-with-python-projects/page-view-time-series-visualizerbox_plot

I am not sure if you have plotted it at the moment. I am going to share my ans with you :slight_smile: Feel free to discuss :slight_smile:

f, axes = plt.subplots(figsize=(12, 7), ncols=2, sharex=False)
sns.despine(left=True)

ax2 = sns.boxplot(x='Years', y='value', data=df_box, ax=axes[0])
ax2.set_xlabel('Year')
ax2.set_ylabel('Page Views')
ax2.set_title('Year-wise Box Plot(Trend)')

ax2 = sns.boxplot(x='Months', y='value', data=df_box, ax=axes[1])
ax2.set_xlabel('Month')
ax2.set_ylabel('Page Views')
ax2.set_title('Month-wise Box Plot(Seasonality)')
3 Likes

How did you prepared the data ? Please, share your code for’df_box’.
Thanks