@@ -19,12 +19,12 @@ class DateConverter(units.ConversionInterface):
19
19
20
20
@staticmethod
21
21
def convert(value, unit, axis):
22
- 'convert value to a scalar or array'
22
+ 'Convert a datetime value to a scalar or array'
23
23
return dates.date2num(value)
24
24
25
25
@staticmethod
26
26
def axisinfo(unit, axis):
27
- 'return major and minor tick locators and formatters'
27
+ 'Return major and minor tick locators and formatters'
28
28
if unit!='date': return None
29
29
majloc = dates.AutoDateLocator()
30
30
majfmt = dates.AutoDateFormatter(majloc)
@@ -34,10 +34,10 @@ def axisinfo(unit, axis):
34
34
35
35
@staticmethod
36
36
def default_units(x, axis):
37
- 'return the default unit for x or None'
37
+ 'Return the default unit for x or None'
38
38
return 'date'
39
39
40
- # Finally we register our object type with a converter
40
+ # Finally we register our object type with the Matplotlib units registry.
41
41
units.registry[datetime.date] = DateConverter()
42
42
43
43
"""
@@ -53,22 +53,24 @@ def default_units(x, axis):
53
53
class AxisInfo (object ):
54
54
"""
55
55
Information to support default axis labeling, tick labeling, and
56
- default limits.
56
+ default limits. An instance of this class must be returned by
57
+ :meth:`ConversionInterface.axisinfo`.
57
58
"""
58
59
def __init__ (self , majloc = None , minloc = None ,
59
60
majfmt = None , minfmt = None , label = None ,
60
61
default_limits = None ):
61
62
"""
62
63
Parameters
63
64
----------
64
- majloc, minloc
65
- TickLocators for the major and minor ticks.
66
- majfmt, minfmt
67
- TickFormatters for the major and minor ticks.
68
- label
65
+ majloc, minloc : Locator, optional
66
+ Tick locators for the major and minor ticks.
67
+ majfmt, minfmt : Formatter, optional
68
+ Tick formatters for the major and minor ticks.
69
+ label : str, optional
69
70
The default axis label.
70
- default_limits
71
- The default min, max of the axis if no data is present.
71
+ default_limits : optional
72
+ The default min and max limits of the axis if no data has
73
+ been plotted.
72
74
73
75
Notes
74
76
-----
@@ -85,7 +87,7 @@ def __init__(self, majloc=None, minloc=None,
85
87
86
88
class ConversionInterface (object ):
87
89
"""
88
- The minimal interface for a converter to take custom instances (or
90
+ The minimal interface for a converter to take custom data types (or
89
91
sequences) and convert them to values Matplotlib can use.
90
92
"""
91
93
@staticmethod
@@ -130,15 +132,16 @@ def is_numlike(x):
130
132
131
133
class Registry (dict ):
132
134
"""
133
- Register types with conversion interface .
135
+ A register that maps types to conversion interfaces .
134
136
"""
135
137
def __init__ (self ):
136
138
dict .__init__ (self )
137
139
self ._cached = {}
138
140
139
141
def get_converter (self , x ):
140
142
"""
141
- Get the converter interface instance for *x*, or ``None``.
143
+ Get the converter for data that has the same type as *x*. If no
144
+ converters are registered for *x*, returns ``None``.
142
145
"""
143
146
144
147
if not len (self ):
@@ -153,6 +156,7 @@ def get_converter(self, x):
153
156
if classx is not None :
154
157
converter = self .get (classx )
155
158
159
+ # If x is an array, look inside the array for data with units
156
160
if isinstance (x , np .ndarray ) and x .size :
157
161
xravel = x .ravel ()
158
162
try :
@@ -174,6 +178,7 @@ def get_converter(self, x):
174
178
converter = self .get_converter (next_item )
175
179
return converter
176
180
181
+ # If we haven't found a converter yet, try to get the first element
177
182
if converter is None :
178
183
try :
179
184
thisx = safe_first_element (x )
0 commit comments