Re: [Matplotlib-users] Colorbar labeling
2010/8/20 Bruce Ford br...@clearscienceinc.com: I have a grid with values ranging from exactly 0.0 and 100.0. When I plot this with colorbar, the base of the colorbar is labeled -0.0. Is this a default for 0.0...to plot it with as a negative number? Any workarounds? How sure are you that the floating point number underneath has really not set the negative bit? Maybe try to .clip() the grid positions before on the numpy level to (0.0, \infty) where 0 arises from a fresh parse of '0.0' by the interpreter, i.e., a really really zero fp number. To clip, you may also use grid *= (grid 0) or similar things of that fashion. I'm not sure if the mistake is implied my your side of the code, but i just hope this helps maybe. The Locator stuff is not soo easy. Friedrich -- Sell apps to millions through the Intel(R) Atom(Tm) Developer Program Be part of this innovative community and reach millions of netbook users worldwide. Take advantage of special opportunities to increase revenue and speed time-to-market. Join now, and jumpstart your future. http://p.sf.net/sfu/intel-atom-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Colorbar labeling
I have a grid with values ranging from exactly 0.0 and 100.0. When I plot this with colorbar, the base of the colorbar is labeled -0.0. Is this a default for 0.0...to plot it with as a negative number? Any workarounds? Bruce --- Bruce W. Ford Clear Science, Inc. -- 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
Re: [Matplotlib-users] Colorbar labeling
On 08/20/2010 05:29 AM, Bruce Ford wrote: I have a grid with values ranging from exactly 0.0 and 100.0. When I plot this with colorbar, the base of the colorbar is labeled -0.0. Is this a default for 0.0...to plot it with as a negative number? Any workarounds? Would you provide a minimal runnable example, please, and specify what mpl version you are using? It is certainly not intended or usual that 0 be displayed as -0. Eric Bruce --- Bruce W. Ford Clear Science, Inc. -- 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
Re: [Matplotlib-users] Colorbar labeling
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. (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') 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 --- 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 2:06 PM, Eric Firing efir...@hawaii.edu wrote: On 08/20/2010 05:29 AM, Bruce Ford wrote: I have a grid with values ranging from exactly 0.0 and 100.0. When I plot this with colorbar, the base of the colorbar is labeled -0.0. Is this a default for 0.0...to plot it with as a negative number? Any workarounds? Would you provide a minimal runnable example, please, and specify what mpl version you are using? It is certainly not intended or usual that 0 be displayed as -0. Eric Bruce --- Bruce W. Ford Clear Science, Inc. -- 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
Re: [Matplotlib-users] Colorbar labeling
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.001 Out[1]: '-0.0' In [2]: %1.1f % 0.001 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
Re: [Matplotlib-users] Colorbar labeling
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 --- 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.001 Out[1]: '-0.0' In [2]: %1.1f % 0.001 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
Re: [Matplotlib-users] Colorbar labeling
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 Firingefir...@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.001 Out[1]: '-0.0' In [2]: %1.1f % 0.001 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