source: qesdi/geoplot/trunk/lib/geoplot/layer_drawer_contour.py @ 5688

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/layer_drawer_contour.py@5688
Revision 5688, 2.3 KB checked in by pnorton, 11 years ago (diff)

Improved the colour bar code so it now accepts the data array instead of just a minimum + maximum. It also now defaults to creating a Normalize instance with vmin=None and vmax=None instead of 0 and 1.

Also modified the layer_drawer objects to use the ColourBar? class instead of implementing it themselves.

Line 
1"""
2An object to draw just the layer (map + grid) from the plot,
3can draw to a file, a string or create an Image object.
4"""
5
6
7import logging
8import Image
9import StringIO
10import thread
11
12from geoplot.contour_drawer import ContourDrawer
13import geoplot.utils as geoplot_utils
14
15from geoplot.layer_drawer import LayerDrawerBase
16
17log = logging.getLogger(__name__)
18
19class LayerDrawerContour(LayerDrawerBase):
20    "Draw only the layer section of the plot"
21   
22    def __init__(self, cdmsVar, gridType='latlon', projection='latlon', cmap = None,  cmapRange=(None,None),
23                 transparent=False, numLines=10, fontSize='medium', labelInterval=1):
24       
25        self._contourDrawer = ContourDrawer()
26        self.numLines = numLines
27        self.cdmsVar = cdmsVar
28        self.fontSize = fontSize
29        self.labelInterval =labelInterval
30       
31        LayerDrawerBase.__init__(self, gridType=gridType, transparent=transparent, cmap=cmap, cmapRange=cmapRange)
32       
33    def _drawToAxes(self, axes, xLimits, yLimits):
34        """
35        Draw the contours onto the axes.
36        """
37       
38        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
39       
40        #if the projection is 'latlon' then no transformation is needed.
41        if self.projection == 'latlon':
42            basemap = None
43        else:
44            map = self._getMap(xLimits, yLimits)
45            basemap = map.basemap       
46       
47        norm = self._cb.getNormalize()
48       
49        self._contourDrawer.draw(axes, grid, normalize=norm, cmap=self._cb.getColourMap(),
50                                 basemap=basemap, fontSize=self.fontSize)
51   
52    ### properties ###
53         
54    def __set_numLines(self, value):
55        self._contourDrawer.numContourLines = value
56   
57    def __get_numLines(self):
58        return self._contourDrawer.numContourLines
59
60    numLines = property(__get_numLines, __set_numLines)
61   
62    def __set_fontSize(self, value):
63        self._fontSize = value
64   
65    def __get_fontSize(self):
66        return self._fontSize
67
68    fontSize = property(__get_fontSize, __set_fontSize)
69   
70   
71    def __set_labelInterval(self, value):
72        self._contourDrawer.contourLabelInterval = value
73   
74    def __get_labelInterval(self):
75        return self._contourDrawer.contourLabelInterval
76
77    labelInterval = property(__get_labelInterval, __set_labelInterval)
78
79       
Note: See TracBrowser for help on using the repository browser.