matplotlib 3.5.1

BackRef

import matplotlib.units as units import matplotlib.dates as dates import matplotlib.ticker 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 AxisInfo(majloc=majloc, majfmt=majfmt, label='date')

@staticmethod def default_units(x, axis): "Return the default unit for x or None." return 'date'

# Finally we register our object type with the Matplotlib units registry. units.registry[datetime.date] = DateConverter()

The classes here provide support for using custom classes with Matplotlib, e.g., those that do not expose the array interface but know how to convert themselves to arrays. It also supports classes with units and units conversion. Use cases include converters for custom objects, e.g., a list of datetime objects, as well as for objects that are unit aware. We don't assume any particular units implementation; rather a units implementation must register with the Registry converter dictionary and provide a ConversionInterface . For example, here is a complete implementation which supports plotting with native datetime objects:

import matplotlib.units as units
import matplotlib.dates as dates
import matplotlib.ticker 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 AxisInfo(majloc=majloc, majfmt=majfmt, label='date')

    @staticmethod
    def default_units(x, axis):
        "Return the default unit for x or None."
        return 'date'

# Finally we register our object type with the Matplotlib units registry.
units.registry[datetime.date] = DateConverter()

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

matplotlib.dates matplotlib.category

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /matplotlib/units.py#0
type: <class 'module'>
Commit: