views:

37

answers:

2

I am using matplotlib for a graphing application. I am trying to create a graph which has strings as X values. I cannot do this ( using plot function ) because it's expecting a numaric value for X.

How can I get string X values ( for example, build-lables as X values ) ?

A: 

Here's one way which i know works, though i would think creating custom symbols is a more natural way accomplish this.

from matplotlib import pyplot as PLT

# make up some data for this example
t = range(8)
s = 7 * t + 5
# make up some data labels which we want to appear in place of the symbols
x = 8 * "dp".split()
y = map(str, range(8))
data_labels = [ i+j for i, j in zip(x, y)]
fig = PLT.figure()
ax1 = fig.add_subplot(111)
ax1.plot(t, s, "o", mfc="#FFFFFF")     # set the symbol color so they are invisible
for a, b, c in zip(t, s, data_labels) :
    ax1.text(a, b, c, color="green")

PLT.show()

So this puts "dp1", "dp2",... in place of each of the original data symbols--in essence creating custom "text symbols" though again i have to believe there's a more direct way to do this in matplotlib (without using Artists).

doug
Thank you for the reply. I found this: class matplotlib.ticker.FixedFormatter(seq), which lets you specify the set of strings as a sequence
+1  A: 

Why not just make the x value some auto-incrementing number and then change the label?

--jed

Jed Daniels