Plot string values in matplotlib


Question

I am using matplotlib for a graphing application. I am trying to create a graph which has strings as the X values. However, the using plot function expects a numeric value for X.

How can I use string X values?

1
9
1/23/2012 12:33:50 PM

You should try xticks

import pylab

names = ['anne','barbara','cathy']
counts = [3230,2002,5456]

pylab.figure(1)
x = range(3)
pylab.xticks(x, names)
pylab.plot(x,counts,"g")

pylab.show()
10
4/11/2013 11:30:02 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon