Skip to content

Commit 303dad4

Browse files
authored
doc fixes (velin and colorbar Other Parameters) (#137)
1 parent 3163fba commit 303dad4

File tree

3 files changed

+136
-107
lines changed

3 files changed

+136
-107
lines changed

mplotutils/_colorbar.py

Lines changed: 128 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -90,102 +90,130 @@ def colorbar(
9090
shrink : None or float in 0..1, default: None.
9191
Fraction of the total height that the colorbar is shrunk. See Note.
9292
**kwargs : keyword arguments
93-
colorbar properties
94-
============ ====================================================
95-
Property Description
96-
============ ====================================================
97-
*extend* [ 'neither' | 'both' | 'min' | 'max' ]
98-
If not 'neither', make pointed end(s) for out-of-
99-
range values. These are set for a given colormap
100-
using the colormap set_under and set_over methods.
101-
*extendfrac* [ *None* | 'auto' | length | lengths ]
102-
If set to *None*, both the minimum and maximum
103-
triangular colorbar extensions with have a length of
104-
5% of the interior colorbar length (this is the
105-
default setting). If set to 'auto', makes the
106-
triangular colorbar extensions the same lengths as
107-
the interior boxes (when *spacing* is set to
108-
'uniform') or the same lengths as the respective
109-
adjacent interior boxes (when *spacing* is set to
110-
'proportional'). If a scalar, indicates the length
111-
of both the minimum and maximum triangular colorbar
112-
extensions as a fraction of the interior colorbar
113-
length. A two-element sequence of fractions may also
114-
be given, indicating the lengths of the minimum and
115-
maximum colorbar extensions respectively as a
116-
fraction of the interior colorbar length.
117-
*extendrect* [ *False* | *True* ]
118-
If *False* the minimum and maximum colorbar extensions
119-
will be triangular (the default). If *True* the
120-
extensions will be rectangular.
121-
*spacing* [ 'uniform' | 'proportional' ]
122-
Uniform spacing gives each discrete color the same
123-
space; proportional makes the space proportional to
124-
the data interval.
125-
*ticks* [ None | list of ticks | Locator object ]
126-
If None, ticks are determined automatically from the
127-
input.
128-
*format* [ None | format string | Formatter object ]
129-
If None, the
130-
:class:`~matplotlib.ticker.ScalarFormatter` is used.
131-
If a format string is given, e.g., '%.3f', that is
132-
used. An alternative
133-
:class:`~matplotlib.ticker.Formatter` object may be
134-
given instead.
135-
*drawedges* [ False | True ] If true, draw lines at color
136-
boundaries.
137-
============ ====================================================
93+
See Other Parameters.
94+
95+
Other Parameters
96+
----------------
97+
location : None or {'left', 'right', 'top', 'bottom'}
98+
The location, relative to the parent Axes, where the colorbar Axes
99+
is created. It also determines the *orientation* of the colorbar
100+
(colorbars on the left and right are vertical, colorbars at the top
101+
and bottom are horizontal). If None, the location will come from the
102+
*orientation* if it is set (vertical colorbars on the right, horizontal
103+
ones at the bottom), or default to 'right' if *orientation* is unset.
104+
105+
orientation : None or {'vertical', 'horizontal'}
106+
The orientation of the colorbar. It is preferable to set the *location*
107+
of the colorbar, as that also determines the *orientation*; passing
108+
incompatible values for *location* and *orientation* raises an exception.
109+
110+
fraction : float, default: 0.15
111+
Fraction of original Axes to use for colorbar.
112+
113+
shrink : float, default: 1.0
114+
Fraction by which to multiply the size of the colorbar.
115+
116+
extend : {'neither', 'both', 'min', 'max'}
117+
Make pointed end(s) for out-of-range values (unless 'neither'). These are
118+
set for a given colormap using the colormap set_under and set_over methods.
119+
120+
extendfrac : {*None*, 'auto', length, lengths}
121+
If set to *None*, both the minimum and maximum triangular colorbar
122+
extensions will have a length of 5% of the interior colorbar length (this
123+
is the default setting).
124+
125+
If set to 'auto', makes the triangular colorbar extensions the same lengths
126+
as the interior boxes (when *spacing* is set to 'uniform') or the same
127+
lengths as the respective adjacent interior boxes (when *spacing* is set to
128+
'proportional').
129+
130+
If a scalar, indicates the length of both the minimum and maximum
131+
triangular colorbar extensions as a fraction of the interior colorbar
132+
length. A two-element sequence of fractions may also be given, indicating
133+
the lengths of the minimum and maximum colorbar extensions respectively as
134+
a fraction of the interior colorbar length.
135+
136+
extendrect : bool, default: False
137+
If *False* the minimum and maximum colorbar extensions will be triangular
138+
(the default). If *True* the extensions will be rectangular.
139+
140+
spacing : {'uniform', 'proportional'}
141+
For discrete colorbars (`.BoundaryNorm` or contours), 'uniform' gives each
142+
color the same space; 'proportional' makes the space proportional to the
143+
data interval.
144+
145+
ticks : None or list of ticks or Locator
146+
If None, ticks are determined automatically from the input.
147+
148+
format : None or str or Formatter
149+
If None, `~.ticker.ScalarFormatter` is used.
150+
Format strings, e.g., ``"%4.2e"`` or ``"{x:.2e}"``, are supported.
151+
An alternative `~.ticker.Formatter` may be given instead.
152+
153+
drawedges : bool
154+
Whether to draw lines at color boundaries.
155+
156+
label : str
157+
The label on the colorbar's long axis.
158+
159+
boundaries, values : None or a sequence
160+
If unset, the colormap will be displayed on a 0-1 scale.
161+
If sequences, *values* must have a length 1 less than *boundaries*. For
162+
each region delimited by adjacent entries in *boundaries*, the color mapped
163+
to the corresponding value in values will be used.
164+
Normally only useful for indexed colors (i.e. ``norm=NoNorm()``) or other
165+
unusual circumstances.
138166
139167
Examples
140168
--------
141-
import matplotlib.pyplot as plt
142-
import mplotutils as mpu
143-
import cartopy.crs as ccrs
169+
>>> import matplotlib.pyplot as plt
170+
>>> import mplotutils as mpu
171+
>>> import cartopy.crs as ccrs
144172
145-
# example with 1 axes
173+
>>> # =========================
174+
>>> # example with 1 axes
146175
147-
f, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()})
148-
h = ax.pcolormesh([[0, 1]])
149-
ax.coastlines()
150-
mpu.colorbar(h, ax)
151-
ax.set_global()
176+
>>> f, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()})
177+
>>> h = ax.pcolormesh([[0, 1]])
178+
>>> ax.coastlines()
179+
>>> mpu.colorbar(h, ax)
180+
>>> ax.set_global()
152181
153-
# =========================
154-
# example with 2 axes
182+
>>> # =========================
183+
>>> # example with 2 axes
155184
156-
f, axs = plt.subplots(2, 1, subplot_kw={"projection": ccrs.PlateCarree()})
185+
>>> f, axs = plt.subplots(2, 1, subplot_kw={"projection": ccrs.PlateCarree()})
157186
158-
for ax in axs:
159-
ax.coastlines()
160-
ax.set_global()
161-
h = ax.pcolormesh([[0, 1]])
187+
>>> for ax in axs:
188+
>>> ax.coastlines()
189+
>>> ax.set_global()
190+
>>> h = ax.pcolormesh([[0, 1]])
162191
163-
cbar = mpu.colorbar(h, axs)
192+
>>> cbar = mpu.colorbar(h, axs)
164193
165-
# =========================
166-
# example with 3 axes & 2 colorbars
194+
>>> # =========================
195+
>>> # example with 3 axes & 2 colorbars
167196
168-
f, axs = plt.subplots(3, 1, subplot_kw={"projection": ccrs.PlateCarree()})
197+
>>> f, axs = plt.subplots(3, 1, subplot_kw={"projection": ccrs.PlateCarree()})
169198
170-
for ax in axs:
171-
ax.coastlines()
172-
ax.set_global()
199+
>>> for ax in axs:
200+
>>> ax.coastlines()
201+
>>> ax.set_global()
173202
174-
h0 = ax.pcolormesh([[0, 1]])
175-
h1 = ax.pcolormesh([[0, 1]])
176-
h2 = ax.pcolormesh([[0, 1]], cmap='Blues')
203+
>>> h0 = ax.pcolormesh([[0, 1]])
204+
>>> h1 = ax.pcolormesh([[0, 1]])
205+
>>> h2 = ax.pcolormesh([[0, 1]], cmap='Blues')
177206
178-
cbar = mpu.colorbar(h, [axs[0], axs[1]], size=0.05)
179-
cbar = mpu.colorbar(h, axs[2], size=0.05)
180-
181-
plt.draw()
207+
>>> cbar = mpu.colorbar(h, [axs[0], axs[1]], size=0.05)
208+
>>> cbar = mpu.colorbar(h, axs[2], size=0.05)
182209
183210
Notes
184211
-----
185212
- ``shift='symmetric', shrink=None`` -> colorbar extends over the whole height
186213
- ``shift='symmetric', shrink=0.1`` -> colorbar is 10 % smaller, and centered
187214
- ``shift=0., shrink=0.1`` -> colorbar is 10 % smaller, and aligned with the bottom
188215
- ``shift=0.1, shrink=None`` -> colorbar is 10 % smaller, and aligned with the top
216+
- the ``anchor`` and ``panchor`` keywords are not supported
189217
190218
See Also
191219
--------
@@ -277,25 +305,25 @@ def _resize_colorbar_vert(
277305
278306
Examples
279307
--------
280-
import matplotlib.pyplot as plt
281-
import mplotutils as mpu
282-
import cartopy.crs as ccrs
308+
>>> import matplotlib.pyplot as plt
309+
>>> import mplotutils as mpu
310+
>>> import cartopy.crs as ccrs
283311
284-
f = plt.figure()
285-
ax = plt.axes(projection=ccrs.PlateCarree())
286-
h = ax.pcolormesh([[0, 1]])
312+
>>> f = plt.figure()
313+
>>> ax = plt.axes(projection=ccrs.PlateCarree())
314+
>>> h = ax.pcolormesh([[0, 1]])
287315
288-
ax.coastlines()
316+
>>> ax.coastlines()
289317
290-
cbax = f.add_axes([0, 0, 0.1, 0.1])
291-
cbar = plt.colorbar(h, orientation='vertical', cax=cbax)
318+
>>> cbax = f.add_axes([0, 0, 0.1, 0.1])
319+
>>> cbar = plt.colorbar(h, orientation='vertical', cax=cbax)
292320
293-
func = mpu._resize_colorbar_vert(cbax, ax)
294-
f.canvas.mpl_connect('draw_event', func)
321+
>>> func = mpu._resize_colorbar_vert(cbax, ax)
322+
>>> f.canvas.mpl_connect('draw_event', func)
295323
296-
ax.set_global()
324+
>>> ax.set_global()
297325
298-
plt.draw()
326+
>>> plt.draw()
299327
300328
See Also
301329
--------
@@ -363,24 +391,24 @@ def _resize_colorbar_horz(
363391
364392
Examples
365393
--------
366-
import matplotlib.pyplot as plt
367-
import mplotutils as mpu
368-
import cartopy.crs as ccrs
394+
>>> import matplotlib.pyplot as plt
395+
>>> import mplotutils as mpu
396+
>>> import cartopy.crs as ccrs
369397
370-
f = plt.figure()
371-
ax = plt.axes(projection=ccrs.PlateCarree())
398+
>>> f = plt.figure()
399+
>>> ax = plt.axes(projection=ccrs.PlateCarree())
372400
373-
ax.coastlines()
401+
>>> ax.coastlines()
374402
375-
cbax = f.add_axes([0, 0, 0.1, 0.1])
376-
cbar = plt.colorbar(h, orientation='horizontal', cax=cbax)
403+
>>> cbax = f.add_axes([0, 0, 0.1, 0.1])
404+
>>> cbar = plt.colorbar(h, orientation='horizontal', cax=cbax)
377405
378-
func = mpu._resize_colorbar_horz(cbax, ax)
379-
f.canvas.mpl_connect('draw_event', func)
406+
>>> func = mpu._resize_colorbar_horz(cbax, ax)
407+
>>> f.canvas.mpl_connect('draw_event', func)
380408
381-
ax.set_global()
409+
>>> ax.set_global()
382410
383-
plt.draw()
411+
>>> plt.draw()
384412
385413
See Also
386414
--------

mplotutils/_savefig.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,3 @@ def monkeypatch():
5151

5252
def undo():
5353
Figure.savefig = savefig_orig
54-
55-
56-
# mpu.savefig.autodraw()

mplotutils/cartopy_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def sample_dataarray(nlon, nlat):
5555
5656
Parameters
5757
----------
58-
nlons : int
58+
nlon : int
5959
Number of longitude grid cells.
60-
nlats : int
60+
nlat : int
6161
Number of latitude grid cells.
6262
6363
Returns
@@ -162,7 +162,9 @@ def ylabel_map(s, *, labelpad=None, size=None, weight=None, y=0.5, ax=None, **kw
162162
-------
163163
h : handle
164164
text handle of the created text field
165-
..note::
165+
166+
Notes
167+
-----
166168
http://stackoverflow.com/questions/35479508/cartopy-set-xlabel-set-ylabel-not-ticklabels
167169
168170
"""
@@ -224,7 +226,9 @@ def xlabel_map(s, *, labelpad=None, size=None, weight=None, x=0.5, ax=None, **kw
224226
-------
225227
h : handle
226228
text handle of the created text field
227-
..note::
229+
230+
Notes
231+
-----
228232
http://stackoverflow.com/questions/35479508/cartopy-set-xlabel-set-ylabel-not-ticklabels
229233
230234
"""

0 commit comments

Comments
 (0)