|
From: Matthias M. <Mat...@gm...> - 2008-01-09 12:31:39
|
Hello list,
Hello Thorsten,
On Wednesday 09 January 2008 11:38, Thorsten Kranz wrote:
> I have a question concerning reformatting of axis-ticks via the
> FuncFormatter-class. In german, it's common to use a comma as separator for
> decimal numbers instead of a dot. To realize it in matplotlib, I do
> something like
>
> >from matplotlib.ticker import FuncFormatter
>
> import pylab
> pylab.figure()
> formatter = FuncFormatter(lambda x,pos: ("%.2f"%x).replace(".",","))
> ax = pylab.axes()
> ax.xaxis.set_major_formatter(formatter)
> ax.yaxis.set_major_formatter(formatter)
> ax.plot(pylab.arange(0,1,0.1),pylab.arange(0,1,0.1))
> This works fine for me,
I had the same idea ;-). The problem is that you have a fixed number of digits
behind the comma, which is not the desirable behaviour during zoom.
I changed the ticker.py/ axes.py files to circumwait this disadvantage. I
attached a patch showing my changes and maybe somebody can test it.
You can activate it using:
ax.ticklabel_format(style='comma')
for an ScalarFormatter
> but I encounter a problem when I do an
> imshow-command with a colorbar. In the imshow-axes, it's o.k., but for the
> colorbar it doesn't really work. I do
>
> cb = pylab.colorbar()
> cb.ax.yaxis.set_major_formatter(formatter)
>
> and, actually, all dots are replaced by com9mata, but the values are also
> changed! E.g. instead of the old values (without formatter) from 0-0.54,
> the
>
> values are increased to 0-0.95.
[...]
> Can anyone explain why it doesn't work out as I expect it to work?
I don't know were the problem comes from. I attached your example in a slitly
modified version and this shows that the problem is not due to your special
formatting. It occurs with matplotlib.ticker.ScalarFormatter, too.
best regards,
Matthias
> Or is there a better, more standard way to substitute the dots by commata?
>
> Thanks,
> Thorsten
|