source: qesdi/geoplot/trunk/lib/geoplot/grid_plot.py @ 5612

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

Have added some code that allows the grid drawer to decide if it should use imshow or pcolormesh to render the grid. This was done to get arround the problem of the grid cells having outlines when pcolormesh is used.

Also implemented a map function that chooses which basemap resolution to use if one isn't set.

Line 
1"""
2plot_base.py
3============
4
5Holds the PlotBase class. This is an abstract baseclass that has all the general functionality to produce a map with an overlayed grid of data. All the inheriting class needs to do is provide methods that set the map and the grid to be used in the plot.
6
7"""
8
9#Standard library imports
10import os
11import sys
12import time
13import logging
14
15from geoplot.plot_base import PlotBase
16from geoplot.grid_drawer import GridDrawer
17
18import geoplot.utils as geoplot_utils
19import geoplot.config as geoplot_config
20
21config = geoplot_config.getConfig()
22log = logging.getLogger(__name__)
23
24_construtorDocString = PlotBase.__init__.__doc__ + \
25"""
26@type    drawValues: boolean
27@keyword drawValues: indicates if values should be drawn in grid boxes
28
29@type    drawValuesFile: string
30@keyword drawValuesFile: indicates if a file should be read to determine which cells to
31    draw values inside. Only used if drawValues and this argument are not False.
32
33@type    valueFormat: a python format string
34@keyword valueFormat: format string for the vlaues drawn in the grid boxs
35
36@type    showGridLines: boolean
37@keyword showGridLines: indicates if the gridlines should be shown on the plot
38"""
39
40class GridPlot(PlotBase):
41    """
42    """
43   
44    #add the grid drawer to the accessable object via __getatttr__ and __setattr__
45    _accessableObjects = ['_gridDrawer']
46    _accessableObjects.extend(PlotBase._accessableObjects)
47   
48    def __init__(self, **kwargs):
49        # docString at top of file #
50       
51        self._gridDrawer = GridDrawer(**self._getArgs(kwargs, GridDrawer.__name__))
52               
53        PlotBase.__init__(self, **kwargs)
54       
55    __init__.doc = _construtorDocString
56       
57    def _drawDiagram(self, map, grid, axes):
58       
59        log.debug("grid.values.min() = %s" % (grid.values.min(),))
60        log.debug("grid.values.max() = %s" % (grid.values.max(),))
61       
62        norm = self._colourBar.getNormalize(dataMin=grid.values.min(), dataMax=grid.values.max())
63        cmap = self._colourBar.getColourMap()
64       
65        self._gridDrawer.draw(axes, grid, limits=(self.xLimits, self.yLimits),
66                              basemap=map.basemap, 
67                              norm=norm, cmap=cmap, 
68                              fontSize=self.fontSize)
69
Note: See TracBrowser for help on using the repository browser.