Skip to content

Commit 0f4e03d

Browse files
committed
Add 'all'/'both'/'neither' options for label sides
1 parent 0a6e5f5 commit 0f4e03d

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

docs/projections.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
# <https://scitools.org.uk/cartopy/docs/latest/gallery/lines_and_polygons/always_circular_stereo.html>`__
187187
# from the cartopy website). To disable this feature, set :rcraw:`geo.round` to
188188
# ``False`` or pass ``round=False` to `~proplot.axes.GeoAxes.format`. Please note
189-
# that cartopy cannot add gridline labels to polar plots with circular boundaries.
189+
# that older versions of cartopy cannot add gridlines to maps bounded by circles.
190190
# * To make things more consistent, the `~proplot.constructor.Proj` constructor
191191
# function lets you supply native `PROJ <https://proj.org>`__ keyword names
192192
# for the cartopy `~cartopy.crs.Projection` classes (e.g., `lon0` instead
@@ -212,15 +212,17 @@
212212
ax2 = fig.subplot(gs[i, 1], proj=proj, backend='basemap') # basemap backend
213213

214214
# Format projections
215-
fig.format(
215+
axs = fig.subplotgrid
216+
axs.format(
216217
land=True,
217218
suptitle='Figure with several projections',
218219
toplabels=('Cartopy examples', 'Basemap examples'),
219220
toplabelweight='normal',
220221
latlines=30, lonlines=60,
221-
lonlabels='b', latlabels='r', # or lonlabels=True, labels=True, etc.
222222
)
223-
fig.subplotgrid[-2:].format(latlines=20, lonlines=30) # dense gridlines for polar plots
223+
axs[:2].format(lonlabels='b', latlabels='r') # or lonlabels=True, lonlabels='bottom',
224+
axs[2:4].format(lonlabels=False, latlabels='both')
225+
axs[4:].format(lonlabels='all', lonlines=30)
224226
pplt.rc.reset()
225227

226228

proplot/axes/geo.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,22 @@
9999
which sides of the map. Use the keyword `labels` to set both at once. The
100100
argument must conform to one of the following options:
101101
102-
1. A boolean. ``True`` indicates the left side for latitudes, bottom
103-
side for longitudes, and ``False`` disables all labels.
104-
2. A string or sequence of strings indicating the side names, e.g.
105-
``'left'`` for latitudes or ``('top', 'bottom')`` for longitudes.
106-
3. A string indicating the side names with single characters, e.g.
107-
``'lr'`` for latitudes or ``'bt'`` for longitudes.
108-
4. A boolean 2-tuple indicating whether to draw labels on the
109-
``(left, right)`` sides for latitudes, or ``(bottom, top)``
110-
sides for longitudes.
111-
5. A boolean 4-tuple indicating whether to draw labels on the
112-
``(left, right, bottom, top)`` sides, as with the basemap
113-
`~mpl_toolkits.basemap.Basemap.drawmeridians` and
114-
`~mpl_toolkits.basemap.Basemap.drawparallels` `labels` keyword.
102+
* A boolean. ``True`` indicates the bottom side for longitudes and
103+
the left side for latitudes, and ``False`` disables all labels.
104+
* A string or sequence of strings indicating the side names, e.g.
105+
``'top'`` for longitudes or ``('left', 'right')`` for latitudes.
106+
* A string indicating the side names with single characters, e.g.
107+
``'bt'`` for longitudes or ``'lr'`` for latitudes.
108+
* A string matching ``'neither'`` (no labels), ``'both'`` (equivalent
109+
to ``'bt'`` for longitudes and ``'lr'`` for latitudes), or ``'all'``
110+
(equivalent to ``'lrbt'``, i.e. all sides).
111+
* A boolean 2-tuple indicating whether to draw labels
112+
on the ``(bottom, top)`` sides for longitudes,
113+
and the ``(left, right)`` sides for latitudes.
114+
* A boolean 4-tuple indicating whether to draw labels on the
115+
``(left, right, bottom, top)`` sides, as with the basemap
116+
`~mpl_toolkits.basemap.Basemap.drawmeridians` and
117+
`~mpl_toolkits.basemap.Basemap.drawparallels` `labels` keyword.
115118
116119
loninline, latinline, inlinelabels : bool, default: :rc:`grid.inlinelabels`
117120
*For cartopy axes only.*
@@ -502,12 +505,18 @@ def _to_label_array(arg, lon=True):
502505
array = [False] * 5
503506
opts = ('left', 'right', 'bottom', 'top', 'geo')
504507
for string in strings:
505-
if string in opts:
508+
if string == 'all':
509+
string = 'lrbt'
510+
elif string == 'both':
511+
string = 'bt' if lon else 'lr'
512+
elif string == 'neither':
513+
string = ''
514+
elif string in opts:
506515
string = string[0]
507-
elif set(string) - set('lrbtg'):
516+
if set(string) - set('lrbtg'):
508517
raise ValueError(
509518
f'Invalid {which}label string {string!r}. Must be one of '
510-
+ ', '.join(map(repr, opts))
519+
+ ', '.join(map(repr, (*opts, 'neither', 'both', 'all')))
511520
+ " or a string of single-letter characters like 'lr'."
512521
)
513522
for char in string:

0 commit comments

Comments
 (0)