Skip to content

Commit 4532139

Browse files
authored
code and docstring updates (#14)
1 parent 00fccf7 commit 4532139

File tree

4 files changed

+86
-99
lines changed

4 files changed

+86
-99
lines changed

mplotutils/cartopy_utils.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ def _is_monotonic(coord, axis=0):
120120

121121

122122
def cyclic_dataarray(da, coord="lon"):
123-
"""Add a cyclic coordinate point to a DataArray along a specified
124-
named coordinate dimension.
123+
"""
124+
Add a cyclic coordinate point to a DataArray along a specified named dimension.
125+
125126
>>> import xarray as xr
126127
>>> data = xr.DataArray([[1, 2, 3], [4, 5, 6]],
127128
... coords={'x': [1, 2], 'y': range(3)},
@@ -131,7 +132,7 @@ def cyclic_dataarray(da, coord="lon"):
131132
array([[1, 2, 3, 1],
132133
[4, 5, 6, 4]])
133134
134-
Note
135+
Notes
135136
-----
136137
After: https://github.com/darothen/plot-all-in-ncfile/blob/master/plot_util.py
137138
@@ -193,7 +194,6 @@ def ylabel_map(s, labelpad=None, size=None, weight=None, y=0.5, ax=None, **kwarg
193194
-------
194195
h : handle
195196
text handle of the created text field
196-
197197
..note::
198198
http://stackoverflow.com/questions/35479508/cartopy-set-xlabel-set-ylabel-not-ticklabels
199199
@@ -259,7 +259,6 @@ def xlabel_map(s, labelpad=None, size=None, weight=None, x=0.5, ax=None, **kwarg
259259
-------
260260
h : handle
261261
text handle of the created text field
262-
263262
..note::
264263
http://stackoverflow.com/questions/35479508/cartopy-set-xlabel-set-ylabel-not-ticklabels
265264
@@ -333,7 +332,7 @@ def yticklabels(
333332
Vertical alignment, default: 'center'.
334333
bbox_props : dict
335334
Properties of the bounding box. Default: dict(ec='none', fc='none')
336-
kwargs : additional arguments
335+
**kwargs : additional arguments
337336
Passed to ax.annotate
338337
339338
"""
@@ -435,7 +434,7 @@ def xticklabels(
435434
Vertical alignment, default: 'top'.
436435
bbox_props : dict
437436
Properties of the bounding box. Default: dict(ec='none', fc='none')
438-
kwargs : additional arguments
437+
**kwargs : additional arguments
439438
Passed to ax.annotate
440439
441440
"""

mplotutils/colorbar_utils.py

+61-68
Original file line numberDiff line numberDiff line change
@@ -44,65 +44,52 @@ def colorbar(
4444
shrink : None or float in 0..1
4545
Fraction of the total height that the colorbar is shrunk.
4646
See Note. Default: None.
47-
48-
Note
49-
----
50-
51-
shift='symmetric', shrink=None -> colorbar extends over the whole height
52-
shift='symmetric', shrink=0.1 -> colorbar is 10 % smaller, and centered
53-
shift=0., shrink=0.1 -> colorbar is 10 % smaller, and aligned
54-
with the bottom
55-
shift=0.1, shrink=None -> colorbar is 10 % smaller, and aligned
56-
with the top
57-
58-
kwargs
59-
------
60-
colorbar properties
61-
============ ====================================================
62-
Property Description
63-
============ ====================================================
64-
*extend* [ 'neither' | 'both' | 'min' | 'max' ]
65-
If not 'neither', make pointed end(s) for out-of-
66-
range values. These are set for a given colormap
67-
using the colormap set_under and set_over methods.
68-
*extendfrac* [ *None* | 'auto' | length | lengths ]
69-
If set to *None*, both the minimum and maximum
70-
triangular colorbar extensions with have a length of
71-
5% of the interior colorbar length (this is the
72-
default setting). If set to 'auto', makes the
73-
triangular colorbar extensions the same lengths as
74-
the interior boxes (when *spacing* is set to
75-
'uniform') or the same lengths as the respective
76-
adjacent interior boxes (when *spacing* is set to
77-
'proportional'). If a scalar, indicates the length
78-
of both the minimum and maximum triangular colorbar
79-
extensions as a fraction of the interior colorbar
80-
length. A two-element sequence of fractions may also
81-
be given, indicating the lengths of the minimum and
82-
maximum colorbar extensions respectively as a
83-
fraction of the interior colorbar length.
84-
*extendrect* [ *False* | *True* ]
85-
If *False* the minimum and maximum colorbar extensions
86-
will be triangular (the default). If *True* the
87-
extensions will be rectangular.
88-
*spacing* [ 'uniform' | 'proportional' ]
89-
Uniform spacing gives each discrete color the same
90-
space; proportional makes the space proportional to
91-
the data interval.
92-
*ticks* [ None | list of ticks | Locator object ]
93-
If None, ticks are determined automatically from the
94-
input.
95-
*format* [ None | format string | Formatter object ]
96-
If None, the
97-
:class:`~matplotlib.ticker.ScalarFormatter` is used.
98-
If a format string is given, e.g., '%.3f', that is
99-
used. An alternative
100-
:class:`~matplotlib.ticker.Formatter` object may be
101-
given instead.
102-
*drawedges* [ False | True ] If true, draw lines at color
103-
boundaries.
104-
============ ====================================================
105-
47+
**kwargs : keyword arguments
48+
colorbar properties
49+
============ ====================================================
50+
Property Description
51+
============ ====================================================
52+
*extend* [ 'neither' | 'both' | 'min' | 'max' ]
53+
If not 'neither', make pointed end(s) for out-of-
54+
range values. These are set for a given colormap
55+
using the colormap set_under and set_over methods.
56+
*extendfrac* [ *None* | 'auto' | length | lengths ]
57+
If set to *None*, both the minimum and maximum
58+
triangular colorbar extensions with have a length of
59+
5% of the interior colorbar length (this is the
60+
default setting). If set to 'auto', makes the
61+
triangular colorbar extensions the same lengths as
62+
the interior boxes (when *spacing* is set to
63+
'uniform') or the same lengths as the respective
64+
adjacent interior boxes (when *spacing* is set to
65+
'proportional'). If a scalar, indicates the length
66+
of both the minimum and maximum triangular colorbar
67+
extensions as a fraction of the interior colorbar
68+
length. A two-element sequence of fractions may also
69+
be given, indicating the lengths of the minimum and
70+
maximum colorbar extensions respectively as a
71+
fraction of the interior colorbar length.
72+
*extendrect* [ *False* | *True* ]
73+
If *False* the minimum and maximum colorbar extensions
74+
will be triangular (the default). If *True* the
75+
extensions will be rectangular.
76+
*spacing* [ 'uniform' | 'proportional' ]
77+
Uniform spacing gives each discrete color the same
78+
space; proportional makes the space proportional to
79+
the data interval.
80+
*ticks* [ None | list of ticks | Locator object ]
81+
If None, ticks are determined automatically from the
82+
input.
83+
*format* [ None | format string | Formatter object ]
84+
If None, the
85+
:class:`~matplotlib.ticker.ScalarFormatter` is used.
86+
If a format string is given, e.g., '%.3f', that is
87+
used. An alternative
88+
:class:`~matplotlib.ticker.Formatter` object may be
89+
given instead.
90+
*drawedges* [ False | True ] If true, draw lines at color
91+
boundaries.
92+
============ ====================================================
10693
10794
Examples
10895
--------
@@ -122,7 +109,6 @@ def colorbar(
122109
123110
ax.set_global()
124111
125-
126112
# =========================
127113
# example with 2 axes
128114
@@ -137,7 +123,6 @@ def colorbar(
137123
138124
cbar.set_label('[°C]', labelpad=10)
139125
140-
141126
# =========================
142127
# example with 3 axes & 2 colorbars
143128
@@ -157,8 +142,16 @@ def colorbar(
157142
158143
plt.draw()
159144
145+
Notes
146+
-----
147+
shift='symmetric', shrink=None -> colorbar extends over the whole height
148+
shift='symmetric', shrink=0.1 -> colorbar is 10 % smaller, and centered
149+
shift=0., shrink=0.1 -> colorbar is 10 % smaller, and aligned
150+
with the bottom
151+
shift=0.1, shrink=None -> colorbar is 10 % smaller, and aligned
152+
with the top
160153
161-
See also
154+
See Also
162155
--------
163156
_resize_colorbar_horz
164157
"""
@@ -247,8 +240,8 @@ def _resize_colorbar_vert(
247240
248241
see 'colorbar'
249242
250-
Example
251-
-------
243+
Examples
244+
--------
252245
import matplotlib.pyplot as plt
253246
import mplotutils as mpu
254247
import cartopy.crs as ccrs
@@ -269,7 +262,7 @@ def _resize_colorbar_vert(
269262
270263
plt.draw()
271264
272-
See also
265+
See Also
273266
--------
274267
_resize_colorbar_horz
275268
"""
@@ -336,8 +329,8 @@ def _resize_colorbar_horz(
336329
337330
see 'colorbar'
338331
339-
Example
340-
-------
332+
Examples
333+
--------
341334
import matplotlib.pyplot as plt
342335
import mplotutils as mpu
343336
import cartopy.crs as ccrs
@@ -357,7 +350,7 @@ def _resize_colorbar_horz(
357350
358351
plt.draw()
359352
360-
See also
353+
See Also
361354
--------
362355
_resize_colorbar_vert
363356
"""

mplotutils/mpl_utils.py

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import matplotlib as mpl
22
import matplotlib.pyplot as plt
33
import numpy as np
4-
import six
54
from matplotlib.colors import from_levels_and_colors
65

7-
# =============================================================================
8-
96

107
def from_levels_and_cmap(levels, cmap, extend="neither"):
118
"""
@@ -23,8 +20,9 @@ def from_levels_and_cmap(levels, cmap, extend="neither"):
2320
The behaviour when a value falls out of range of the given levels.
2421
See :func:`~matplotlib.pyplot.contourf` for details.
2522
26-
..note::
27-
Adapted from xarray.
23+
Notes
24+
-----
25+
Adapted from xarray.
2826
2927
"""
3028
if np.isscalar(levels):
@@ -47,14 +45,11 @@ def from_levels_and_cmap(levels, cmap, extend="neither"):
4745
return cmap, norm
4846

4947

50-
# -----------------------------------------------------------------------------
51-
52-
# _color_palette is adapted from xarray:
53-
# https://github.com/pydata/xarray/blob/v0.10.2/xarray/plot/utils.py#L110
54-
# Used under the terms of xarrays's license, see licenses/XARRAY_LICENSE.
55-
56-
5748
def _color_palette(cmap, n_colors):
49+
# _color_palette is adapted from xarray:
50+
# https://github.com/pydata/xarray/blob/v0.10.2/xarray/plot/utils.py#L110
51+
# Used under the terms of xarrays's license, see licenses/XARRAY_LICENSE.
52+
5853
import matplotlib.pyplot as plt
5954
from matplotlib.colors import ListedColormap
6055

@@ -63,7 +58,7 @@ def _color_palette(cmap, n_colors):
6358
# we have a list of colors
6459
cmap = ListedColormap(cmap, N=n_colors)
6560
pal = cmap(colors_i)
66-
elif isinstance(cmap, six.string_types):
61+
elif isinstance(cmap, str):
6762
# we have some sort of named palette
6863
try:
6964
# is this a matplotlib cmap?
@@ -86,9 +81,6 @@ def _color_palette(cmap, n_colors):
8681
return pal
8782

8883

89-
# =============================================================================
90-
91-
9284
def set_map_layout(axes, width=17.0, nrow=None, ncol=None):
9385
"""
9486
set figure height, given width
@@ -108,7 +100,9 @@ def set_map_layout(axes, width=17.0, nrow=None, ncol=None):
108100
ncol : integer, default: None
109101
As nrow but for the number of rows.
110102
111-
..note: only works if all the axes have the same aspect ratio.
103+
Notes
104+
-----
105+
Only works if all the axes have the same aspect ratio.
112106
"""
113107

114108
if (nrow is None and ncol is not None) or (nrow is not None and ncol is None):
@@ -151,9 +145,6 @@ def set_map_layout(axes, width=17.0, nrow=None, ncol=None):
151145
f.set_figheight(height / 2.54)
152146

153147

154-
# =============================================================================
155-
156-
157148
def _get_label_attr(labelpad, size, weight):
158149

159150
if labelpad is None:

requirements.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
numpy
2-
matplotlib
3-
six
4-
cartopy
1+
# This file is redundant with setup.cfg;
2+
# it exists to let GitHub build the repository dependency graph
3+
# https://help.github.com/en/github/visualizing-repository-data-with-graphs/listing-the-packages-that-a-repository-depends-on
4+
5+
cartopy >= 0.17
6+
matplotlib >= 3.2
7+
numpy >= 1.17
8+
setuptools >= 40.4 # for pkg_resources

0 commit comments

Comments
 (0)