as
ticker
import
datetime
class
DateConverter
(
units
.
ConversionInterface
):
@staticmethod
def
convert
(
value
,
unit
,
axis
):
"Convert a datetime value to a scalar or array."
return
dates
.
date2num
(
value
)
@staticmethod
def
axisinfo
(
unit
,
axis
):
"Return major and minor tick locators and formatters."
if
unit
!=
'date'
:
return
None
majloc
=
dates
.
AutoDateLocator
()
majfmt
=
dates
.
AutoDateFormatter
(
majloc
)
return
units
.
AxisInfo
(
majloc
=
majloc
,
majfmt
=
majfmt
,
label
=
'date'
)
@staticmethod
def
default_units
(
x
,
axis
):
"Return the default unit for x or None."
return
'date'
units
.
registry
[
datetime
.
date
]
=
DateConverter
()
-
class matplotlib.units.AxisInfo(majloc=None, minloc=None, majfmt=None, minfmt=None, label=None, default_limits=None)
Bases: object
Information to support default axis labeling, tick labeling, and limits.
An instance of this class must be returned by
ConversionInterface.axisinfo.
- Parameters:
- majloc, minloc : Locator, optional
Tick locators for the major and minor ticks.
- majfmt, minfmt : Formatter, optional
Tick formatters for the major and minor ticks.
- label : str, optional
The default axis label.
- default_limits : optional
The default min and max limits of the axis if no data has
been plotted.
Notes
If any of the above are None, the axis will simply use the
default value.
-
exception matplotlib.units.ConversionError
Bases: TypeError
-
class matplotlib.units.ConversionInterface
Bases: object
The minimal interface for a converter to take custom data types (or
sequences) and convert them to values Matplotlib can use.
-
static axisinfo(unit, axis)
Return an AxisInfo for the axis with the specified units.
-
static convert(obj, unit, axis)
Convert obj using unit for the specified axis.
If obj is a sequence, return the converted sequence. The output must
be a sequence of scalars that can be used by the numpy array layer.
-
static default_units(x, axis)
Return the default unit for x or None for the given axis.
-
class matplotlib.units.DecimalConverter
Bases: ConversionInterface
Converter for decimal.Decimal data to float.
-
static convert(value, unit, axis)
Convert Decimals to floats.
The unit and axis arguments are not used.
- Parameters:
- value : decimal.Decimal or iterable
Decimal or list of Decimal need to be converted
-
class matplotlib.units.Registry
Bases: dict
Register types with conversion interface.
-
get_converter(x)
Get the converter interface instance for x, or None.