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

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

First attempt at adding the contour plot. I've tried to re-use existing components where possible. There is still a lot of duplication between the contour plot base and plot base classes.

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 matplotlib.colors import Normalize
13
14from geoplot.contour_drawer import ContourDrawer
15import geoplot.utils as geoplot_utils
16
17from geoplot.layer_drawer import LayerDrawerBase
18
19log = logging.getLogger(__name__)
20
21class LayerDrawerContour(LayerDrawerBase):
22    "Draw only the layer section of the plot"
23   
24    def __init__(self, cdmsVar, gridType='latlon', projection='latlon', cmap = None,  cmapRange=(None,None),
25                 transparent=False, numLines=10, fontSize='medium', labelInterval=1):
26       
27        self._contourDrawer = ContourDrawer()
28       
29        self.cmap = cmap
30        self.numLines = numLines
31        self.cmapRange = cmapRange
32        self.cdmsVar = cdmsVar
33        self.fontSize = fontSize
34        self.labelInterval =labelInterval
35       
36        LayerDrawerBase.__init__(self, gridType, transparent, projection)
37       
38    def _drawToAxes(self, axes, xLimits, yLimits):
39        """
40        Draw the contours onto the axes.
41        """
42       
43        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
44       
45        #if the projection is 'latlon' then no transformation is needed.
46        if self.projection == 'latlon':
47            basemap = None
48        else:
49            map = self._getMap(xLimits, yLimits)
50            basemap = map.basemap       
51       
52        norm = Normalize(self.cmapRange[0], self.cmapRange[1])
53        self._contourDrawer.draw(axes, grid, normalize=norm, cmap=self.cmap,
54                                 basemap=basemap, fontSize=self.fontSize)
55   
56    ### properties ###
57       
58    def __set_cmap(self, value):
59        self._cmap = value
60       
61    def __get_cmap(self):
62        return self._cmap
63   
64    cmap = property(__get_cmap, __set_cmap)
65   
66    def __set_numLines(self, value):
67        self._contourDrawer.numContourLines = value
68   
69    def __get_numLines(self):
70        return self._contourDrawer.numContourLines
71
72    numLines = property(__get_numLines, __set_numLines)
73   
74    def __set_fontSize(self, value):
75        self._fontSize = value
76   
77    def __get_fontSize(self):
78        return self._fontSize
79
80    fontSize = property(__get_fontSize, __set_fontSize)
81   
82   
83    def __set_labelInterval(self, value):
84        self._contourDrawer.contourLabelInterval = value
85   
86    def __get_labelInterval(self):
87        return self._contourDrawer.contourLabelInterval
88
89    labelInterval = property(__get_labelInterval, __set_labelInterval)
90
91    def __set_cmapRange(self, value):
92        self._cmapRange = value
93       
94    def __get_cmapRange(self):
95        return self._cmapRange
96   
97    cmapRange = property(__get_cmapRange, __set_cmapRange)   
98       
Note: See TracBrowser for help on using the repository browser.