Tell us what’s happening:
I’ve looked through other post on this project in the forum search for “must have the same dimension”
This is the error I’m getting:
Traceback (most recent call last):
File “main.py”, line 6, in
time_series_visualizer.draw_line_plot()
Traceback (most recent call last):
File “main.py”, line 6, in
time_series_visualizer.draw_line_plot()
Traceback (most recent call last):
File “main.py”, line 6, in
time_series_visualizer.draw_line_plot()
File “/home/runner/Time-Series/time_series_visualizer.py”, line 16, in draw_line_plot
plt.plot(‘date’, ‘value’, data=df)
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/pyplot.py”, line 2785, in plot
return gca().plot(
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/axes/_axes.py”, line 1688, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py”, line 311, in call
yield from self._plot_args(
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py”, line 504, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (1,) and (1238,)
Describe your issue in detail here.
Your code so far
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()Import data (Make sure to parse dates. Consider setting index column to ‘date’.)
df = pd.read_csv(“fcc-forum-pageviews.csv”)
df.sort_values(by=“date”, inplace=True)
df.set_index(‘date’, inplace=True)Clean data
df = df[(df[‘value’] >= df[‘value’].quantile(0.025)) & (df[‘value’] <= df[‘value’].quantile(0.975))]
def draw_line_plot():
fig, ax = plt.subplots()
plt.plot(‘date’, ‘value’, data=df)
plt.title(“Daily freeCodeCamp Forum Page Views 5/2016-12/2019”)
plt.xlabel(“Date”)
plt.ylabel(“Page Views”)# Save image and return fig (don't change this part)
fig.savefig(‘line_plot.png’)
return figdef draw_bar_plot():
# Copy and modify data for monthly bar plot
df[‘date’]= pd.to_datetime(df[‘date’])
df_bar[‘year’] = pd.DatetimeIndex(df_bar[‘date’]).year
df_bar[‘month’] = pd.DatetimeIndex(df_bar[‘date’]).month_name()df_bar = df.groupby([df['date'].dt.year, df['date'].dt.month]).mean() # Draw bar plot sns.barplot(data=df_bar, x="year", y="value", hue="month_name") plt.xlabel("Year") plt.ylabel("Average Page Views") plt.legend(loc='upper left') # Save image and return fig (don't change this part) fig.savefig('bar_plot.png') return fig
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) seaborn.boxplot(data=None, *, x=None, y=None, hue=None) # 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Challenge: Data Analysis with Python Projects - Page View Time Series Visualizer
Link to the challenge: