Skip to content

Commit

Permalink
Adding deprecations for gridliner labels on/off.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglucas committed Apr 4, 2020
1 parent 411b98c commit f2ff5bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docs/source/matplotlib/gridliner.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Cartopy map gridlines and tick labels
Cartopy map gridlines and tick labels
=====================================

The :class:`~cartopy.mpl.gridliner.Gridliner` instance, often created by calling the
:meth:`cartopy.mpl.geoaxes.GeoAxes.gridlines` method on a
The :class:`~cartopy.mpl.gridliner.Gridliner` instance, often created by calling the
:meth:`cartopy.mpl.geoaxes.GeoAxes.gridlines` method on a
:class:`cartopy.mpl.geoaxes.GeoAxes` instance, has a variety of attributes which can be
used to determine draw time behaviour of the gridlines and labels.

Expand All @@ -11,14 +11,14 @@ used to determine draw time behaviour of the gridlines and labels.
The current :class:`~cartopy.mpl.gridliner.Gridliner` interface is likely to undergo
a significant change in the versions following v0.6 in order to fix some of the underying
limitations of the current implementation.


.. autoclass:: cartopy.mpl.gridliner.Gridliner
:members:
:undoc-members:



The following contrived example makes use of many of the features of the Gridliner
class to produce customized gridlines and tick labels:

Expand All @@ -28,22 +28,22 @@ class to produce customized gridlines and tick labels:
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs

from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER


ax = plt.axes(projection=ccrs.Mercator())
ax.coastlines()
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=2, color='gray', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_left = False
gl.top_labels = False
gl.left_labels = False
gl.xlines = False
gl.xlocator = mticker.FixedLocator([-180, -45, 0, 45, 180])
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': 15, 'color': 'gray'}
gl.xlabel_style = {'color': 'red', 'weight': 'bold'}

plt.show()
40 changes: 40 additions & 0 deletions lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,46 @@ def __init__(self, axes, crs, draw_labels=False, xlocator=None,
# (or once drawn, only at resize event ?)
self.axes.figure.canvas.mpl_connect('draw_event', self._draw_event)

@property
def xlabels_top(self):
return self.top_labels

@xlabels_top.setter
def xlabels_top(self, value):
warnings.warn('The .xlabels_top attribute is deprecated. Please '
'use .top_labels to toggle visibility instead.')
self.top_labels = value

@property
def xlabels_bottom(self):
return self.bottom_labels

@xlabels_bottom.setter
def xlabels_bottom(self, value):
warnings.warn('The .xlabels_bottom attribute is deprecated. Please '
'use .bottom_labels to toggle visibility instead.')
self.bottom_labels = value

@property
def ylabels_left(self):
return self.left_labels

@ylabels_left.setter
def ylabels_left(self, value):
warnings.warn('The .ylabels_left attribute is deprecated. Please '
'use .left_labels to toggle visibility instead.')
self.left_labels = value

@property
def ylabels_right(self):
return self.right_labels

@ylabels_right.setter
def ylabels_right(self, value):
warnings.warn('The .ylabels_right attribute is deprecated. Please '
'use .right_labels to toggle visibility instead.')
self.right_labels = value

def _draw_event(self, event):
if self.has_labels():
self._update_labels_visibility(event.renderer)
Expand Down

0 comments on commit f2ff5bd

Please sign in to comment.