Matplotlib Ticker

Viewed 8033

Can someone give me an example of how to use the following tickFormatters. The docs are uninformative to me.

ticker.StrMethodFormatter() ticker.IndexFormatter()

for example I might think that

x = np.array([ 316566.962,  294789.545,  490032.382,  681004.044,  753757.024,
            385283.153,  651498.538,  937628.225,  199561.358,  601465.455])
y = np.array([ 208.075,  262.099,  550.066,  633.525,  612.804,  884.785,
            862.219,  349.805,  279.964,  500.612])
money_formatter = tkr.StrMethodFormatter('${:,}')

plt.scatter(x,y)
ax = plt.gca()
fmtr = ticker.StrMethodFormatter('${:,}')
ax.xaxis.set_major_formatter(fmtr)

would set my tick labels to be dollar signed and comma sep for thousands places ala

['$300,000', '$400,000', '$500,000', '$600,000', '$700,000', '$800,000', '$900,000']

but instead I get an index error.

IndexError: tuple index out of range

For IndexFormatter docs say:

Set the strings from a list of labels

don't really know what this means and when I try to use it my tics disappear.

1 Answers
Related