I am visualizing my data in bar, column, line and scatter chart using matplotlib for the first time. I am getting an error whenever I am mentioning the x and y axis. Here is my code below for all charts,

df.plot.bar(pd.DatetimeIndex(df['date']), y=df[value])
df.plot.bar(pd.DatetimeIndex(df['date']), y=df[value])
df.plot.line(pd.DatetimeIndex(df['date']), y=df[value])
df.plot.scatter(x=pd.DatetimeIndex(df['date']), y=df[value])
plt.show()

I have found similar issue in datetime index KeyError: 'the label [2000-01-03 00:00:00] is not in the [index]'. But it is not solving my problem.

1

There are 1 best solutions below

0
On BEST ANSWER

I found my mistake what I did. I need to define the x and y axis by the column name without mentioning like df['date']. However, I have visualized the scatter plot using scatter_matrix. So the workable code is,

df.plot.bar(pd.DatetimeIndex(x='date', y='value')
df.plot.bar(pd.DatetimeIndex(x='date', y='value')
df.plot.line(pd.DatetimeIndex(x='date', y='value')
scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')
plt.show()