Skip to content

Commit

Permalink
Ensure that gridline labels are only drawn once (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Oct 8, 2019
1 parent be4d220 commit 769b565
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions geoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ def __init__(self, element, **params):
self.aspect = 'equal'

def _finalize_axis(self, *args, **kwargs):
ret = super(GeoOverlayPlot, self)._finalize_axis(*args, **kwargs)
gridlabels = self.geographic and isinstance(self.projection, (ccrs.PlateCarree, ccrs.Mercator))
if gridlabels:
xaxis, yaxis = self.xaxis, self.yaxis
self.xaxis = self.yaxis = None
try:
ret = super(GeoOverlayPlot, self)._finalize_axis(*args, **kwargs)
except Exception as e:
raise e
finally:
if gridlabels:
self.xaxis, self.yaxis = xaxis, yaxis

axis = self.handles['axis']
if self.show_grid:
axis.grid()
Expand Down Expand Up @@ -144,13 +155,25 @@ def _process_grid(self, gl):
gl.yformatter = wrap_formatter(self.yformatter)

def _finalize_axis(self, *args, **kwargs):
ret = super(GeoPlot, self)._finalize_axis(*args, **kwargs)
axis = self.handles['axis']
gridlabels = self.geographic and isinstance(self.projection, (ccrs.PlateCarree, ccrs.Mercator))
if gridlabels:
xaxis, yaxis = self.xaxis, self.yaxis
self.xaxis = self.yaxis = None
try:
# Only PlateCarree and Mercator plots support grid labels.
gl = axis.gridlines(draw_labels=True)
except TypeError:
gl = axis.gridlines()
ret = super(GeoPlot, self)._finalize_axis(*args, **kwargs)
except Exception as e:
raise e
finally:
if gridlabels:
self.xaxis, self.yaxis = xaxis, yaxis

axis = self.handles['axis']
# Only PlateCarree and Mercator plots support grid labels.
if 'gridlines' in self.handles:
gl = self.handles['gridlines']
else:
self.handles['gridlines'] = gl = axis.gridlines(
draw_labels=gridlabels and self.zorder == 0)
self._process_grid(gl)

if self.global_extent:
Expand Down

0 comments on commit 769b565

Please sign in to comment.