Re: [Matplotlib-users] FuncFormatter and Colorbar

2008-01-16 Thread Thorsten Kranz
Hi MAtthias,

yes, I can confirm this behavior. This is what I get as well. But the
solution is easy: just get rid of th line

cb.ax.yaxis.set_major_formatter(formatter)

We don't need it anymore and it messes it all up. Without it, it should
work.

Greetings,
Thorsten

2008/1/11, Matthias Michler [EMAIL PROTECTED]:

 Hi Thorsten,

 On Wednesday 09 January 2008 15:35, Thorsten Kranz wrote:
  Hi list, Hi Matthias,
 
  I found another way to deal with this problem. when defining the
 colorbar,
  one can give an additional kwarg format, so by defining the kwarg
  format=formatter, we solved the problem.

 I'm happy that your problem disappeared, but I still have a question. On
 my
 system the problem still exist, if I use format=formatter in colorbar
 and
 after that use
 cb.ax.yaxis.set_major_formatter(formatter)
 in the example-code of my last email.
 Can anybody confirm this behaviour (data range 0.0 ... 0.54 - 0.0 ...
 0.95)?
 And if so: Is this the expected behaviour?

 best regards,
 Matthias


  Anyway, I think an option as Matthias implemented would be very handy
 for
  all those users like us here in Germany who might want to have the
 numbers
  formatted with commata.
 
  Greetings,
  Thorsten
 
  2008/1/9, Matthias Michler [EMAIL PROTECTED]:
   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
  
  
 -
   Check out the new SourceForge.net Marketplace.
   It's the best place to buy or sell services for
   just about anything Open Source.
  
  
 http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl
  ace ___
   Matplotlib-users mailing list
   Matplotlib-users@lists.sourceforge.net
   https://lists.sourceforge.net/lists/listinfo/matplotlib-users

 -
 Check out the new SourceForge.net Marketplace.
 It's the best place to buy or sell services for
 just about anything Open Source.

 http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] FuncFormatter and Colorbar

2008-01-11 Thread Matthias Michler
Hi Thorsten,

On Wednesday 09 January 2008 15:35, Thorsten Kranz wrote:
 Hi list, Hi Matthias,

 I found another way to deal with this problem. when defining the colorbar,
 one can give an additional kwarg format, so by defining the kwarg
 format=formatter, we solved the problem.

I'm happy that your problem disappeared, but I still have a question. On my 
system the problem still exist, if I use format=formatter in colorbar and 
after that use 
cb.ax.yaxis.set_major_formatter(formatter)
in the example-code of my last email. 
Can anybody confirm this behaviour (data range 0.0 ... 0.54 - 0.0 ... 0.95)? 
And if so: Is this the expected behaviour?

best regards,
Matthias


 Anyway, I think an option as Matthias implemented would be very handy for
 all those users like us here in Germany who might want to have the numbers
 formatted with commata.

 Greetings,
 Thorsten

 2008/1/9, Matthias Michler [EMAIL PROTECTED]:
  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
 
  -
  Check out the new SourceForge.net Marketplace.
  It's the best place to buy or sell services for
  just about anything Open Source.
 
  http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl
 ace ___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] FuncFormatter and Colorbar

2008-01-09 Thread Thorsten Kranz
Hi to all!

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, 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. The complete code for this example would be:

from matplotlib.ticker import FuncFormatter, ScalarFormatter
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)
data = pylab.zeros((100,100),d)
data[10,10] = 0.567
pylab.imshow(data)
cb = pylab.colorbar()
cb.ax.yaxis.set_major_formatter(formatter)

Can anyone explain why it doesn't work out as I expect it to work? Or is
there a better, more standard way to substitute the dots by commata?

Thanks,
Thorsten
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] FuncFormatter and Colorbar

2008-01-09 Thread Matthias Michler
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
Index: ticker.py
===
--- ticker.py	(revision 4805)
+++ ticker.py	(working copy)
@@ -272,13 +272,15 @@
 such that the tick labels are meaningful. Scientific notation is used for
 data  1e-3 or data = 1e4.
 
-def __init__(self, useOffset=True, useMathText=False):
+def __init__(self, useOffset=True, useMathText=False, useComma=False):
 # useOffset allows plotting small data ranges with large offsets:
 # for example: [1+1e-9,1+2e-9,1+3e-9]
 # useMathText will render the offset and scientific notation in mathtext
+# useComma leads to comma (',') as decimal separator
 self._useOffset = useOffset
 self._usetex = rcParams['text.usetex']
 self._useMathText = useMathText
+self._useComma = useComma
 self.offset = 0
 self.orderOfMagnitude = 0
 self.format = ''
@@ -327,11 +329,17 @@
 if self.offset:
 offsetStr = self.format_data(self.offset)
 if self.offset  0: offsetStr = '+' + offsetStr
+if self._useComma:
+if self._usetex:
+offsetStr = offsetStr.replace('.','{,}')
+else:
+offsetStr = offsetStr.replace('.',',')
 if self.orderOfMagnitude:
 if self._usetex or self._useMathText:
 sciNotStr = r'{\times}'+self.format_data(10**self.orderOfMagnitude)
 else:
 sciNotStr = u'\xd7'+'1e%d'% self.orderOfMagnitude
+
 if self._useMathText:
 return ''.join(('$\mathdefault{',sciNotStr,offsetStr,'}$'))
 elif self._usetex:
@@ -406,7 +414,13 @@
 def pprint_val(self, x):
 xp = (x-self.offset)/10**self.orderOfMagnitude
 if npy.absolute(xp)  1e-8: xp = 0
-return self.format % xp
+if self._useComma:
+if self._usetex:
+return (self.format % xp).replace('.','{,}')
+else:
+return (self.format % xp).replace('.',',')
+else:
+return self.format % xp
 
 def _formatSciNotation(self, s):
 # transform 1e+004 into 1e4, for example
Index: axes.py
===
--- axes.py	(revision 4805)
+++ axes.py	(working copy)
@@ -1438,8 +1438,9 @@
 used by default for linear axes.
 
 kwargs:
-style = 'sci' (or 'scientific') or 'plain';
-plain turns off scientific notation
+style = 'sci' (or 'scientific') or 'plain' or 'comma';
+plain/comma turns off scientific notation
+comma enables decimal seperator ','
 axis = 'x', 'y', or 'both'
 
 Only the major ticks are affected.
@@ -1452,15 +1453,13 @@
 
 style = kwargs.pop('style', '').lower()
 axis = kwargs.pop('axis', 'both').lower()
+cb = False
 if style[:3] == 'sci':
 sb = True
 elif style in 

Re: [Matplotlib-users] FuncFormatter and Colorbar

2008-01-09 Thread Thorsten Kranz
Hi list, Hi Matthias,

I found another way to deal with this problem. when defining the colorbar,
one can give an additional kwarg format, so by defining the kwarg
format=formatter, we solved the problem.

Anyway, I think an option as Matthias implemented would be very handy for
all those users like us here in Germany who might want to have the numbers
formatted with commata.

Greetings,
Thorsten

2008/1/9, Matthias Michler [EMAIL PROTECTED]:

 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

 -
 Check out the new SourceForge.net Marketplace.
 It's the best place to buy or sell services for
 just about anything Open Source.

 http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users