Data Analysis with Python Projects - Page View Time Series Visualizer

Tell us what’s happening:
Describe your issue in detail here.
I keep getting the error "expected line plot xlabel to be ‘Date’ when running main.py, but I don’t understand why, as my xlabel is very explicitly set to ‘Date’, as far as I can tell.

replit page

Your code so far
def draw_line_plot():
# Draw line plot
fig, ax = plt.subplots(figsize=(32, 10), dpi=100)
ax.set_title(“Daily freeCodeCamp Forum Page Views 5/2016-12/2019”)
ax.set_xlabel(‘Date’)
ax.set_ylabel(‘Page Views’)
sns.lineplot(data=df, legend=False)

# Save image and return fig (don't change this part)
fig.savefig('line_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/104.0.0.0 Safari/537.36

Challenge: Data Analysis with Python Projects - Page View Time Series Visualizer

Link to the challenge:

You are changing the axis label when you call sns.lineplot() after ax.set_xlabel() here:

def draw_line_plot():
  # Draw line plot
  fig, ax = plt.subplots(figsize=(32, 10), dpi=100)
  ax.set_title("Daily freeCodeCamp Forum Page Views 5/2016-12/2019")
  ax.set_xlabel('Date')
  ax.set_ylabel('Page Views')
  sns.lineplot(data=df, legend=False)

sns.lineplot() (and all the sns methods) use the column name of the dataframe by default when creating plots and your dataframe has a ‘date’ (not ‘Date’) column.

Ah, I see. Good to know. So something like this should do the trick then:

fig, ax = plt.subplots(figsize=(32, 10), dpi=100)

ax.plot(df.index, df[‘value’], ‘r’, linewidth=1)

ax.set_title(“Daily freeCodeCamp Forum Page Views 5/2016-12/2019”)
ax.set_xlabel(‘Date’)
ax.set_ylabel(‘Page Views’)

… and… yep, passed this time. Thanks!

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