On 08/20/2010 10:51 AM, Bruce Ford wrote:
> Thanks I'll give this a try.  numpy.min(grid) reports 0.0 (no
> negative) yet it labels as -0.0, BTW, but let me give this a try.

Bruce,

What matters is not min(grid), but the value of the tick. Unless you are 
forcing them to be the same via a kwarg (which I don't see), they may 
differ, as seems to be the case.  Unfortunately, this is hard to debug, 
because there is no way to get at the set of numbers that are being 
formatted to give the tick labels.  Doing something like this:

print cbar.cax.get_yticks()

will be of no help, because the tick positions are on a 0-1 scale 
regardless of the values they represent.

You can, however, specify the desired tick values as a sequence via the 
ticks kwarg to colorbar.  Ticks in that sequence but outside the actual 
colorbar range (as set by the clim() function, for example) will not appear.

Eric

>
> Bruce
>
> ---------------------------------------
> Bruce W. Ford
> Clear Science, Inc.
> br...@clearscienceinc.com
> http://www.ClearScienceInc.com
> http://www.facebook.com/clearscience
> http://www.twitter.com/ROVs_rule
> Phone: (904) 796-8101
> Fax:  (904) 379-9704
> 8241 Parkridge Circle N.
> Jacksonville, FL  32211
> Skype:  bruce.w.ford
>
> ---------------------------------------
> To schedule a meeting with Bruce, Go to: http://tungle.me/bruceford
> ----------------------------------------
>
>
>
>
> On Fri, Aug 20, 2010 at 4:44 PM, Eric Firing<efir...@hawaii.edu>  wrote:
>> On 08/20/2010 10:14 AM, Bruce Ford wrote:
>>> This effect is happening within an web app that displays gridded
>>> fields from multiple datasets (~4500 lines of code).  So I it's tricky
>>> to create an example.  Although if I use numpy.min(grid) the minimum
>>> is 0.  So, I think colorbar or matplotlib is interpreting the 0 as -0.
>>
>>
>> You are talking about the colorbar tick labels, correct?  The lowest
>> tick label is coming out as -0.0?
>>
>>
>>>    (Matplotlib version 0.99.0 RC0)
>>>
>>> The colorbar call that I'm using is:
>>>
>>> cbar = pyplot.colorbar(plot,shrink=0.7, format="%1.1f",
>>> spacing='proportional',orientation='vertical')
>>
>> This means your colorbar tick values are simply being formatted by
>> python, like this:
>>
>> In [1]: "%1.1f" % -0.0000001
>> Out[1]: '-0.0'
>>
>> In [2]: "%1.1f" % 0.0000001
>> Out[2]: '0.0'
>>
>> In [3]: "%1.1f" % 0.0
>> Out[3]: '0.0'
>>
>> In [4]: "%1.1f" % -0.0
>> Out[4]: '-0.0'
>>
>> In [5]: import numpy
>>
>> In [6]: numpy.min(-0.0)
>> Out[6]: -0
>>
>> In [7]: -0.0 == 0.0
>> Out[7]: True
>>
>>
>> So I suspect the problem is that a small negative value, or a negative
>> zero, is becoming the tick value.  I don't know why.  You may or may not
>> want to investigate.
>>
>> I dimly recall a problem like this cropping up on the list before--but I
>> don't remember anything else about it.
>>
>> Here is a workaround (untested, but should be close):
>>
>> from matplotlib.ticker import FormatStrFormatter
>> class MyCBFormatter(FormatStrFormatter):
>>      def __call__(self, x, pos=None):
>>          xstr = self.fmt % x
>>          if float(xstr) == 0:
>>              return self.fmt % 0
>>          return xstr
>> cbar = pyplot.colorbar(plot,shrink=0.7, format=MyCBFormatter("%1.1f"),
>>           spacing='proportional',orientation='vertical')
>>
>>
>> Eric
>>
>>>
>>> cbar.ax.set_ylabel(cbar_label(param,unit))
>>>
>>> The function cbar_label is:
>>>
>>> def cbar_label(param,unit):
>>>       #Helper function for making colorbar label
>>>       if param == "sig":
>>>           if unit==1:
>>>               cbar_label = "Feet"
>>>           else:
>>>               cbar_label = "Meters"
>>>       elif param == "dir":
>>>           cbar_label = "Radial Direction"
>>>       elif param == "per":
>>>           cbar_label = "Seconds"
>>>       elif param[-5:] == "_wind":
>>>           if unit == 3:
>>>               cbar_label = "Kts"
>>>           else:
>>>               cbar_label = "M/S"
>>>       elif param[-4:] == "_hgt":
>>>           if unit == 5:
>>>               cbar_label = "GPFt"
>>>           else:
>>>               cbar_label = "GPM"
>>>       elif param == "slp":
>>>           cbar_label = "Millibars"
>>>       elif param == "1000_rh":
>>>           cbar_label = "%"
>>>       elif param == "1000_temp":
>>>           if unit == 9:
>>>               cbar_label = "Degrees F"
>>>           else:
>>>               cbar_label = "Degrees C"
>>>       else:
>>>           cbar_label = param
>>>       return cbar_label
>>>
>>> If this doesn't offer anything, I'll try to generate a
>>> compartmentalized example of the issue.
>>>
>>> Bruce
>>
>> ------------------------------------------------------------------------------
>> 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
>>
>
> ------------------------------------------------------------------------------
> 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


------------------------------------------------------------------------------
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