2

I wish to plot the time variation of my y-axis variable using Matplotlib. This is no problem for continuously discrete data, however how should this be tackled for non-continuous data.

I.e. if I wanted to visualise the times at which my car was stationary on the way to work the x-axis would be time and the y-axis would be comprised of the variables 'stationary' and 'moving' (pretty useless example i know)

The non-continuous data would need to be indexed somehow, but i don't know how to proceed...any ideas?

2
  • 1
    In that particular example, it's just a step function - stationary or moving. So what wrong with 0=stationary, 1=moving? Commented Apr 26, 2010 at 17:41
  • Perhaps norm does not want the vertical lines in that step function? Commented Apr 26, 2010 at 17:49

1 Answer 1

7

Is this the type of thing you want? (If not, you might want to check out the matplotlib gallery page to give yourself some ideas, or maybe just draw a picture and post it.)

import matplotlib.pyplot as plt

data = [0]*5 + [1]*10 + [0]*3 +[1]*2

print data

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(data)
ax.set_yticks((0, 1.))
ax.set_yticklabels(('stopped', 'moving'))
ax.set_ybound((-.2, 1.2))
ax.set_xlabel("time (minutes)")

plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

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.