Skip to content

Commit 8464167

Browse files
committed
Clean up units.py
1 parent db1cde0 commit 8464167

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

lib/matplotlib/units.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
22
The classes here provide support for using custom classes with
3-
matplotlib, e.g., those that do not expose the array interface but know
3+
Matplotlib, e.g., those that do not expose the array interface but know
44
how to convert themselves to arrays. It also supports classes with
55
units and units conversion. Use cases include converters for custom
66
objects, e.g., a list of datetime objects, as well as for objects that
77
are unit aware. We don't assume any particular units implementation;
88
rather a units implementation must provide the register with the Registry
9-
converter dictionary and a ConversionInterface. For example,
9+
converter dictionary and a `ConversionInterface`. For example,
1010
here is a complete implementation which supports plotting with native
1111
datetime objects::
1212
@@ -37,7 +37,7 @@ def default_units(x, axis):
3737
'return the default unit for x or None'
3838
return 'date'
3939
40-
# finally we register our object type with a converter
40+
# Finally we register our object type with a converter
4141
units.registry[datetime.date] = DateConverter()
4242
4343
"""
@@ -51,17 +51,29 @@ def default_units(x, axis):
5151

5252

5353
class AxisInfo(object):
54-
"""information to support default axis labeling and tick labeling, and
55-
default limits"""
54+
"""
55+
Information to support default axis labeling, tick labeling, and
56+
default limits.
57+
"""
5658
def __init__(self, majloc=None, minloc=None,
5759
majfmt=None, minfmt=None, label=None,
5860
default_limits=None):
5961
"""
60-
majloc and minloc: TickLocators for the major and minor ticks
61-
majfmt and minfmt: TickFormatters for the major and minor ticks
62-
label: the default axis label
63-
default_limits: the default min, max of the axis if no data is present
64-
If any of the above are None, the axis will simply use the default
62+
Parameters
63+
----------
64+
majloc, minloc :
65+
TickLocators for the major and minor ticks.
66+
majfmt, minfmt :
67+
TickFormatters for the major and minor ticks.
68+
label :
69+
The default axis label
70+
default_limits :
71+
The default min, max of the axis if no data is present
72+
73+
Notes
74+
-----
75+
If any of the above are ``None``, the axis will simply use the
76+
default value.
6577
"""
6678
self.majloc = majloc
6779
self.minloc = minloc
@@ -74,37 +86,37 @@ def __init__(self, majloc=None, minloc=None,
7486
class ConversionInterface(object):
7587
"""
7688
The minimal interface for a converter to take custom instances (or
77-
sequences) and convert them to values mpl can use
89+
sequences) and convert them to values Matplotlib can use.
7890
"""
7991
@staticmethod
8092
def axisinfo(unit, axis):
81-
'return an units.AxisInfo instance for axis with the specified units'
93+
'''
94+
Return an `~units.AxisInfo` instance for axis with the specified units.
95+
'''
8296
return None
8397

8498
@staticmethod
8599
def default_units(x, axis):
86-
'return the default unit for x or None for the given axis'
100+
'Return the default unit for *x* or ``None`` for the given axis.'
87101
return None
88102

89103
@staticmethod
90104
def convert(obj, unit, axis):
91105
"""
92-
convert obj using unit for the specified axis. If obj is a sequence,
93-
return the converted sequence. The output must be a sequence of
94-
scalars that can be used by the numpy array layer
106+
Convert *obj* using *unit* for the specified *axis*.
107+
If *obj* is a sequence, return the converted sequence.
108+
The output must be a sequence of scalars that can be used by the numpy
109+
array layer.
95110
"""
96111
return obj
97112

98113
@staticmethod
99114
def is_numlike(x):
100115
"""
101-
The matplotlib datalim, autoscaling, locators etc work with
116+
The Matplotlib datalim, autoscaling, locators etc work with
102117
scalars which are the units converted to floats given the
103118
current unit. The converter may be passed these floats, or
104-
arrays of them, even when units are set. Derived conversion
105-
interfaces may opt to pass plain-ol unitless numbers through
106-
the conversion interface and this is a helper function for
107-
them.
119+
arrays of them, even when units are set.
108120
"""
109121
if iterable(x):
110122
for thisx in x:
@@ -115,14 +127,14 @@ def is_numlike(x):
115127

116128
class Registry(dict):
117129
"""
118-
register types with conversion interface
130+
Register types with conversion interface.
119131
"""
120132
def __init__(self):
121133
dict.__init__(self)
122134
self._cached = {}
123135

124136
def get_converter(self, x):
125-
'get the converter interface instance for x, or None'
137+
'Get the converter interface instance for *x*, or ``None``.'
126138

127139
if not len(self):
128140
return None # nothing registered
@@ -153,7 +165,7 @@ def get_converter(self, x):
153165
# not ever return a non-subclass for a single element.
154166
next_item = xravel[0]
155167
if (not isinstance(next_item, np.ndarray) or
156-
next_item.shape != x.shape):
168+
next_item.shape != x.shape):
157169
converter = self.get_converter(next_item)
158170
return converter
159171

0 commit comments

Comments
 (0)