16
16
17
17
__all__ = ['arange' , 'edges' , 'edges2d' , 'units' ]
18
18
19
- BENCHMARK = False # change this to turn on benchmarking
20
- NUMBER = re .compile ('^([-+]?[0-9._]+([eE][-+]?[0-9_]+)?)(.*)$' )
19
+ # Change this to turn on benchmarking
20
+ BENCHMARK = False
21
+
22
+ # Units regex
23
+ NUMBER = re .compile ('^([-+]?[0-9._]+(?:[eE][-+]?[0-9_]+)?)(.*)$' )
21
24
22
25
23
26
class _benchmark (object ):
@@ -239,7 +242,7 @@ def edges2d(Z):
239
242
return Zb
240
243
241
244
242
- def units (value , units = 'in' , axes = None , figure = None , width = True ):
245
+ def units (value , dest = 'in' , axes = None , figure = None , width = True ):
243
246
"""
244
247
Convert values and lists of values between arbitrary physical units. This
245
248
is used internally all over ProPlot, permitting flexible units for various
@@ -249,7 +252,7 @@ def units(value, units='in', axes=None, figure=None, width=True):
249
252
----------
250
253
value : float or str or list thereof
251
254
A size specifier or *list thereof*. If numeric, nothing is done.
252
- If string, it is converted to `units` units. The string should look
255
+ If string, it is converted to the units `dest` . The string should look
253
256
like ``'123.456unit'``, where the number is the magnitude and
254
257
``'unit'`` is one of the following.
255
258
@@ -274,12 +277,12 @@ def units(value, units='in', axes=None, figure=None, width=True):
274
277
``'ly'`` Light years ;)
275
278
========= =========================================================================================
276
279
277
- units : str, optional
280
+ dest : str, optional
278
281
The destination units. Default is inches, i.e. ``'in'``.
279
282
axes : `~matplotlib.axes.Axes`, optional
280
- The axes to use for scaling units that look like ``0.1ax``.
283
+ The axes to use for scaling units that look like ``' 0.1ax' ``.
281
284
figure : `~matplotlib.figure.Figure`, optional
282
- The figure to use for scaling units that look like ``0.1fig``. If
285
+ The figure to use for scaling units that look like ``' 0.1fig' ``. If
283
286
``None`` we try to get the figure from ``axes.figure``.
284
287
width : bool, optional
285
288
Whether to use the width or height for the axes and figure relative
@@ -330,10 +333,10 @@ def units(value, units='in', axes=None, figure=None, width=True):
330
333
unit_dict ['fig' ] = figure .get_size_inches ()[1 - int (width )]
331
334
# Scale for converting inches to arbitrary other unit
332
335
try :
333
- scale = unit_dict [units ]
336
+ scale = unit_dict [dest ]
334
337
except KeyError :
335
338
raise ValueError (
336
- f'Invalid destination units { units !r} . Valid units are '
339
+ f'Invalid destination units { dest !r} . Valid units are '
337
340
+ ', ' .join (map (repr , unit_dict .keys ())) + '.'
338
341
)
339
342
@@ -355,10 +358,11 @@ def units(value, units='in', axes=None, figure=None, width=True):
355
358
f'Invalid size spec { val !r} . Valid units are '
356
359
+ ', ' .join (map (repr , unit_dict .keys ())) + '.'
357
360
)
358
- number , _ , units = regex .groups () # second group is exponential
361
+ number , units = regex .groups () # second group is exponential
359
362
try :
360
363
result .append (
361
- float (number ) * (unit_dict [units ] / scale if units else 1 ))
364
+ float (number ) * (unit_dict [units ] / scale if units else 1 )
365
+ )
362
366
except (KeyError , ValueError ):
363
367
raise ValueError (
364
368
f'Invalid size spec { val !r} . Valid units are '
0 commit comments