如何在 Matplotlib 中绘制非数字数据 [英] How to plot non-numeric data in Matplotlib

查看:38
本文介绍了如何在 Matplotlib 中绘制非数字数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 Matplotlib 绘制 y 轴变量的时间变化.这对于连续离散的数据没有问题,但是对于非连续数据应该如何解决.

即如果我想想象我的车在上班途中静止的时间,x 轴将是时间,y 轴将由变量静止"和移动"组成(我知道这是一个非常无用的例子)

非连续数据需要以某种方式建立索引,但是我不知道该如何进行...任何想法?

解决方案

这是您想要的类型吗?(如果没有,您可能想查看 matplotlib

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?

解决方案

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

这篇关于如何在 Matplotlib 中绘制非数字数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆