Movatterモバイル変換


[0]ホーム

URL:


You are reading an old version of the documentation (v2.0.0). For the latest version seehttps://matplotlib.org/stable/api/units_api.html
matplotlib

Navigation


Travis-CI:

Table Of Contents

Related Topics

This Page

Quick search

units

matplotlib.units

The classes here provide support for using custom classes withmatplotlib, e.g., those that do not expose the array interface but knowhow to converter themselves to arrays. It also supoprts classes withunits and units conversion. Use cases include converters for customobjects, e.g., a list of datetime objects, as well as for objects thatare unit aware. We don’t assume any particular units implementation,rather a units implementation must provide a ConversionInterface, andthe register with the Registry converter dictionary. For example,here is a complete implementation which supports plotting with nativedatetime objects:

importmatplotlib.unitsasunitsimportmatplotlib.datesasdatesimportmatplotlib.tickerastickerimportdatetimeclassDateConverter(units.ConversionInterface):@staticmethoddefconvert(value,unit,axis):'convert value to a scalar or array'returndates.date2num(value)@staticmethoddefaxisinfo(unit,axis):'return major and minor tick locators and formatters'ifunit!='date':returnNonemajloc=dates.AutoDateLocator()majfmt=dates.AutoDateFormatter(majloc)returnAxisInfo(majloc=majloc,majfmt=majfmt,label='date')@staticmethoddefdefault_units(x,axis):'return the default unit for x or None'return'date'# finally we register our object type with a converterunits.registry[datetime.date]=DateConverter()
classmatplotlib.units.AxisInfo(majloc=None,minloc=None,majfmt=None,minfmt=None,label=None,default_limits=None)

Bases:object

information to support default axis labeling and tick labeling, anddefault limits

majloc and minloc: TickLocators for the major and minor ticksmajfmt and minfmt: TickFormatters for the major and minor tickslabel: the default axis labeldefault_limits: the default min, max of the axis if no data is presentIf any of the above are None, the axis will simply use the default

classmatplotlib.units.ConversionInterface

Bases:object

The minimal interface for a converter to take custom instances (orsequences) and convert them to values mpl can use

staticaxisinfo(unit,axis)

return an units.AxisInfo instance for axis with the specified units

staticconvert(obj,unit,axis)

convert obj using unit for the specified axis. If obj is a sequence,return the converted sequence. The ouput must be a sequence of scalarsthat can be used by the numpy array layer

staticdefault_units(x,axis)

return the default unit for x or None for the given axis

staticis_numlike(x)

The matplotlib datalim, autoscaling, locators etc work withscalars which are the units converted to floats given thecurrent unit. The converter may be passed these floats, orarrays of them, even when units are set. Derived conversioninterfaces may opt to pass plain-ol unitless numbers throughthe conversion interface and this is a helper function forthem.

classmatplotlib.units.Registry

Bases:dict

register types with conversion interface

get_converter(x)

get the converter interface instance for x, or None

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team. Last updated on Feb 20, 2017. Created usingSphinx 1.5.2.

[8]ページ先頭

©2009-2025 Movatter.jp