On Tue, Aug 17, 2010 at 11:06 PM, Jeremy Conlin <jlcon...@gmail.com> wrote:
> On Mon, Aug 16, 2010 at 6:13 PM, Jae-Joon Lee <lee.j.j...@gmail.com> wrote:
>> Using the set_powerlimits method didn't help?
>
> I couldn't get set_powerlimits or set_scientific to change anything in
> my colorbar scaling.  If I used setOffset(False) then there was no
> scaling; an improvement, but not ideal.
>
>>
>> As far as I know, the current implementation does not allow a custom
>> scale factor.
>> But if the scale factor is power of 10 (10, 100, 1000, ...), I believe
>> using set_powerlimits method (as in my previous example, or some
>> variation) is good enough.
>
> Unfortunately in my simple example (and in my real world case), the
> scale factor is some number (i.e. 5) times a power of 10.
>
> Am I missing something?  I'm running matplotlib version 1.0.0.
>
> Thanks,
> Jeremy
>
>
>
> import numpy
> import matplotlib.pyplot as pyplot
>
> a = 5000
> b = 5002
>
> M = (b-a)*numpy.random.random((5,5))+a
>
> fig = pyplot.figure()
> pc = pyplot.pcolor(M)
>
> cbar = fig.colorbar(pc)
> cbar.formatter.set_scientific(False)
> cbar.formatter.set_powerlimits((0,2))
> # cbar.formatter.set_useOffset(False)
>
> cbar.update_ticks()
>

Try


cbar.formatter.set_useOffset(False)
cbar.formatter.set_scientific(True)
cbar.formatter.set_powerlimits((0,2))

It gives me

offsetText -> "x 10^3"
and tick labels = ["5.0002", "5.0004",...]

which I believe is what you want?

In case you want a scaling factor other than some power of tens, I
guess the easiest way is to scale the image itself and then use
"annotate" command to put the offsetText.

For example,

import numpy
import matplotlib.pyplot as pyplot

a = 5000
b = 5002

M = (b-a)*numpy.random.random((5,5))+a

fig = pyplot.figure()
pc = pyplot.pcolor(M/5000)

cbar = fig.colorbar(pc)

cbar.formatter.set_useOffset(False)

cbar.ax.annotate(r"$\times 5000$",
                 (0.5, 1), xytext=(0, 5),
                 xycoords="axes fraction", textcoords="offset points")

cbar.update_ticks()


-JJ

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to