source: qesdi/geoplot/trunk/lib/geoplot/fixed_boundary_norm.py @ 5699

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/fixed_boundary_norm.py@5699
Revision 5699, 847 bytes checked in by pnorton, 10 years ago (diff)

Extended geoplot so it can now create a discrete colour bar with named labels instead of a continuouse one.

I've also modified the layer drawing code to fix a transparency bug and to make more use of the new colourbar features.

Line 
1'''
2Created on 8 Sep 2009
3
4@author: pnorton
5
6There seems to be a problem with the current version of matplotlib and
7numpy that causes the BoundaryNorm code to fail when called with a single
8element array, implemented as simple class to fix this case.
9
10'''
11from numpy import ma
12from matplotlib.colors import BoundaryNorm
13import logging
14
15log = logging.getLogger(__name__)
16
17class FixedBoundaryNorm(BoundaryNorm):
18   
19    def __init__(self, *args, **kwargs):
20        BoundaryNorm.__init__(self, *args, **kwargs)
21       
22    def __call__(self,x, clip=None):
23        log.debug("x.shape = %s" % (x.shape,))
24       
25        if x.shape == ():
26            for i, b in enumerate(self.boundaries):
27                if x >= b:
28                    ret = i
29            return ma.array(ret)
30        else:
31            return BoundaryNorm.__call__(self, x, clip)
Note: See TracBrowser for help on using the repository browser.