开发者

How to plot non-numeric data in Matplotlib

I wish to plot the time variation开发者_如何学C 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?


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()

How to plot non-numeric data in Matplotlib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜