0

For some reason I can't get my data plotted on the 'x'axis, and I can't get column name printed on the 'y' axis. I've tried a number of variations to the 'df.plot()' line over the past week without success.

Here is my code:

data = [['2018/10/11',1000],['2018/10/12',2000],['2018/10/13',1500]]    
df = pd.DataFrame(data,columns=['Date','Amount'])
df.plot(x='Date', y='Amount')
plt.show()

Here is my output:

2
  • Have you tried plt.ylabel('Amount') for the axis label? Commented Nov 9, 2018 at 16:47
  • Dear Gules, I hope you found the answers given below to be helpful. Please consider accepting one of the many answers given if you found them useful. =) Commented Nov 28, 2018 at 4:28

2 Answers 2

1

You would want to convert your strings to datetime, e.g. via pd.to_datetime.

import pandas as pd
import matplotlib.pyplot as plt

data = [['2018/10/11',1000],['2018/10/12',2000],['2018/10/13',1500]]    
df = pd.DataFrame(data,columns=['Date','Amount'])
df["Date"] = pd.to_datetime(df["Date"], format="%Y/%m/%d")
df.plot(x='Date', y='Amount')
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

0

You can try this:

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

data = [['2018/10/11',1000],['2018/10/12',2000],['2018/10/13',1500]]  
df = pd.DataFrame(data, columns=['Date','Amount'])

xx = np.arange(len(df.values[:,0]))
# xx = [0 1 2]

yy = df.values[:,1]
# yy = [1000 2000 1500]

plt.scatter(x=xx, y=yy)
plt.xlabel('Dates')
plt.ylabel('Amount')
plt.tight_layout()
plt.show()

You will get the following plot:enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.