Logo Search packages:      
Sourcecode: matplotlib version File versions

matplotlib::units Namespace Reference

Detailed Description

The classes here provide support for using custom classes with
matplotlib, eg those that do not expose the array interface but know
how to converter themselves to arrays.  It also supoprts classes with
units and units conversion.  Use cases include converters for custom
objects, eg 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 provide a ConversionInterface, and
the register with the Registry converter dictionary.  For example,
here is a complete implementation which support 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):

    def convert(value, unit):
        'convert value to a scalar or array'
        return dates.date2num(value)
    convert = staticmethod(convert)

    def axisinfo(unit):
        'return major and minor tick locators and formatters'
        if unit!='date': return None
        majloc = dates.AutoDateLocator()
        majfmt = dates.AutoDateFormatter(majloc)
        return AxisInfo(majloc=majloc,
    axisinfo = staticmethod(axisinfo)

    def default_units(x):
        'return the default unit for x or None'
        return 'date'
    default_units = staticmethod(default_units)

# finally we register our object type with a converter
units.registry[datetime.date] = DateConverter()


class  AxisInfo
class  ConversionInterface
class  Registry


tuple registry = Registry()

Generated by  Doxygen 1.6.0   Back to index