0

I am trying to make a graph having 3 points on Y and time on x-axis. The data is given as:

0.00059642,0.00060012,0.00059642,0.00060012,1112.25854421,2017-10-11T19:45:00,0.66505583
0.00060011,0.00060012,0.00059642,0.00059922,3637.58805798,2017-10-11T19:50:00,2.17918273
0.00059922,0.00059999,0.00059922,0.00059922,395.62320194,2017-10-11T19:55:00,0.23722457
0.00059922,0.00059999,0.00058506,0.00059518,4551.22115392,2017-10-11T20:00:00,2.70701959

Code is given below:

time = data['T']
data['T'] = pd.to_datetime(time)
plt.figure(figsize=(9, 5))
plt.plot(data['Close'], lw=1, label='ARK CLOSE')
plt.plot(data['MA_5'], 'g', lw=1, label='5-day SMA (green)')
plt.plot(data['MA_20'], 'y', lw=2, label='20-day SMA (red)')
plt.xticks(data['T'])
plt.setp(plt.gca().get_xticklabels(), rotation=30)
plt.show()

on xticks I am getting the error.

2 Answers 2

1

It cannot transform timestamp to a numeric value required to define the position on the axis. However, you do not need this since you just want constant distances, as I understand it.

You can do

plt.xticks(np.arange(4), data["T"], rotation=30)
Sign up to request clarification or add additional context in comments.

Comments

0

What about letting matplotlib take care of the dates on the x axis,

data['T'] = pd.to_datetime(data['T'])
plt.figure(figsize=(9, 5))
plt.plot(data['T'],data['Close'], lw=1, label='ARK CLOSE')
plt.plot(data['T'],data['MA_5'], 'g', lw=1, label='5-day SMA (green)')
plt.plot(data['T'],data['MA_20'], 'y', lw=2, label='20-day SMA (red)')

plt.setp(plt.gca().get_xticklabels(), rotation=30)
plt.show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.