Hi, Does anyone know how to use FuncFormatter class to
> translate the tick labels using a user defined function?
> I have on my xaxis the code of my weather stations and I
> have defined a function to replace them with their
> station names. The function uses just a dictionary.
> When I tried to apply "FuncFormatter(func)" it didn't
> work.
> No results found searching for examples or recipes
grep -l FuncFormatter examples/*.py
examples/custom_ticker1.py
#!/usr/bin/env python
from matplotlib.ticker import FuncFormatter
from pylab import *
x = arange(4)
money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]
def millions(x, pos):
'The two args are the value and tick position'
return '$%1.1fM' % (x*1e-6)
formatter = FuncFormatter(millions)
ax = subplot(111)
ax.yaxis.set_major_formatter(formatter)
bar(x, money)
xticks( x + 0.5, ('Bill', 'Fred', 'Mary', 'Sue') )
show()