Skip to content

Commit

Permalink
Added is_global option to set global plot extent (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 13, 2018
1 parent 8f483ed commit 8021085
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ def _init_glyph(self, plot, mapping, properties):

class FeaturePlot(GeoPolygonPlot):

apply_ranges = param.Boolean(default=False, doc="""
Whether to compute the plot bounds from the data itself.""")

scale = param.ObjectSelector(default='110m',
objects=['10m', '50m', '110m'],
doc="The scale of the Feature in meters.")
Expand Down
7 changes: 7 additions & 0 deletions geoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class GeoPlot(ElementPlot):
BoxZoomTool(match_aspect=True), 'reset'],
doc="A list of plugin tools to use on the plot.")

is_global = param.Boolean(default=False, doc="""
Whether the plot should display the whole globe.""")

show_grid = param.Boolean(default=False, doc="""
Whether to show gridlines on the plot.""")

Expand Down Expand Up @@ -96,6 +99,8 @@ def get_extents(self, element, ranges):
set_extent method to project the extents to the
Elements coordinate reference system.
"""
if self.is_global:
return (-20026376.39, -20048966.10, 20026376.39, 20048966.10)
extents = super(GeoPlot, self).get_extents(element, ranges)
if not getattr(element, 'crs', None) or not self.geographic:
return extents
Expand All @@ -121,6 +126,8 @@ class OverlayPlot(GeoPlot, HvOverlayPlot):
for geographic plots.
"""

_propagate_options = HvOverlayPlot._propagate_options + ['is_global']

def __init__(self, element, **params):
super(OverlayPlot, self).__init__(element, **params)
self.geographic = any(element.traverse(is_geographic, [_Element]))
Expand Down
27 changes: 23 additions & 4 deletions geoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,33 @@ class LayoutPlot(ProjectionPlot, HvLayoutPlot):



class OverlayPlot(ProjectionPlot, HvOverlayPlot):
class GeoOverlayPlot(ProjectionPlot, HvOverlayPlot):
"""
Extends HoloViews OverlayPlot with functionality to determine
the correct projection for each axis.
"""

is_global = param.Boolean(default=False, doc="""
Whether the plot should display the whole globe.""")

_propagate_options = HvOverlayPlot._propagate_options + ['is_global']

def __init__(self, element, **params):
super(OverlayPlot, self).__init__(element, **params)
super(GeoOverlayPlot, self).__init__(element, **params)
plot_opts = self.lookup_options(self.hmap.last, 'plot').options
self.geographic = any(self.hmap.traverse(is_geographic, [Element]))
if 'aspect' not in plot_opts and self.geographic:
self.aspect = 'equal'

def _finalize_axis(self, *args, **kwargs):
ret = super(GeoOverlayPlot, self)._finalize_axis(*args, **kwargs)
axis = self.handles['axis']
if self.show_grid:
axis.gridlines()
if self.is_global:
axis.set_global()
return ret



class GeoPlot(ProjectionPlot, ElementPlot):
Expand All @@ -115,6 +129,9 @@ class GeoPlot(ProjectionPlot, ElementPlot):
apply_ranges = param.Boolean(default=False, doc="""
Do not use ranges to compute plot extents by default.""")

is_global = param.Boolean(default=False, doc="""
Whether the plot should display the whole globe.""")

projection = param.Parameter(default=ccrs.PlateCarree())

# Project operation to apply to the element
Expand Down Expand Up @@ -166,9 +183,11 @@ def get_extents(self, element, ranges):

def _finalize_axis(self, *args, **kwargs):
ret = super(GeoPlot, self)._finalize_axis(*args, **kwargs)
axis = self.handles['axis']
if self.show_grid:
axis = self.handles['axis']
axis.gridlines()
if self.is_global:
axis.set_global()
return ret


Expand Down Expand Up @@ -544,7 +563,7 @@ def draw_annotation(self, axis, data, crs, opts):
Text: GeoTextPlot,
Layout: LayoutPlot,
NdLayout: LayoutPlot,
Overlay: OverlayPlot,
Overlay: GeoOverlayPlot,
Polygons: GeoPolygonPlot,
Path: GeoPathPlot,
Contours: GeoContourPlot,
Expand Down

0 comments on commit 8021085

Please sign in to comment.