How to plot non-numeric data in Matplotlib
I want to plot the time variation of a y-axis variable using Matplotlib. This is not a problem for continuous discrete data, but how it should be addressed for non-continuous data.
those. if I wanted to visualize the times in which my car was on the way to work, the x-axis would be time and the y-axis would be made up of the variables "stationary" and "moving" (pretty useless example that I know)
Continuous data needs to be indexed somehow, but I don't know how to proceed ... any ideas?
+2
a source to share
1 answer
Is this the type of thing you want? (If not, you can check the matplotlib gallery page to give yourself some ideas or 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()
+6
a source to share
