neuniversity / ALY6140

1 stars 3 forks source link

ValueError: x and y must have same first dimension #41

Open ruanqing976 opened 5 years ago

ruanqing976 commented 5 years ago

Hi,

How to solve Matplotlib error ValueError that ask for the same first dimension?

ValueError: x and y must have same first dimension, but have shapes (100,) and (21902,)

Code: import pandas as pd import numpy as np import matplotlib.pyplot as plt

df1w = df1.head(100)

plt.plot(df1w['total earnings'], df1w['regular'], '.') plt.plot(df1w['total earnings'], results.fittedvalues, '.') plt.legend(['actual regular', 'predicted regular'])

CHENGYULIU1 commented 5 years ago

What is the shape of results.fittedvalues? This works since I tried it on my dataset: plt.plot(df1w['total earnings'], df1w['regular'], '.'). I am guessing plt.plot(df1w['total earnings'], results.fittedvalues, '.') has some issues. You might go check the shape of each series.

Iris0114 commented 5 years ago

Hi I think the error message means that you should have the same dimension for your x and y array. Because python will use your x,y pair to locate a dot to plot.

ruanqing976 commented 5 years ago

What is the shape of results.fittedvalues? This works since I tried it on my dataset: plt.plot(df1w['total earnings'], df1w['regular'], '.'). I am guessing plt.plot(df1w['total earnings'], results.fittedvalues, '.') has some issues. You might go check the shape of each series.

Thank you for your help!

ruanqing976 commented 5 years ago

Hi I think the error message means that you should have the same dimension for your x and y array. Because python will use your x,y pair to locate a dot to plot.

Thank you for your help!