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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users