当前位置: 首页>>代码示例>>Python>>正文


Python units.registry方法代码示例

本文整理汇总了Python中matplotlib.units.registry方法的典型用法代码示例。如果您正苦于以下问题:Python units.registry方法的具体用法?Python units.registry怎么用?Python units.registry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.units的用法示例。


在下文中一共展示了units.registry方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_numpy_facade

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def test_numpy_facade(quantity_converter):
    # Register the class
    munits.registry[Quantity] = quantity_converter

    # Simple test
    y = Quantity(np.linspace(0, 30), 'miles')
    x = Quantity(np.linspace(0, 5), 'hours')

    fig, ax = plt.subplots()
    fig.subplots_adjust(left=0.15)  # Make space for label
    ax.plot(x, y, 'tab:blue')
    ax.axhline(Quantity(26400, 'feet'), color='tab:red')
    ax.axvline(Quantity(120, 'minutes'), color='tab:green')
    ax.yaxis.set_units('inches')
    ax.xaxis.set_units('seconds')

    assert quantity_converter.convert.called
    assert quantity_converter.axisinfo.called
    assert quantity_converter.default_units.called


# Tests gh-8908 
开发者ID:holzschu,项目名称:python3_ios,代码行数:24,代码来源:test_units.py

示例2: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register(explicit=True):
    """
    Register Pandas Formatters and Converters with matplotlib

    This function modifies the global ``matplotlib.units.registry``
    dictionary. Pandas adds custom converters for

    * pd.Timestamp
    * pd.Period
    * np.datetime64
    * datetime.datetime
    * datetime.date
    * datetime.time

    See Also
    --------
    deregister_matplotlib_converter
    """
    # Renamed in pandas.plotting.__init__
    global _WARN

    if explicit:
        _WARN = False

    pairs = get_pairs()
    for type_, cls in pairs:
        converter = cls()
        if type_ in units.registry:
            previous = units.registry[type_]
            _mpl_units[type_] = previous
        units.registry[type_] = converter 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:_converter.py

示例3: deregister

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def deregister():
    """
    Remove pandas' formatters and converters

    Removes the custom converters added by :func:`register`. This
    attempts to set the state of the registry back to the state before
    pandas registered its own units. Converters for pandas' own types like
    Timestamp and Period are removed completely. Converters for types
    pandas overwrites, like ``datetime.datetime``, are restored to their
    original value.

    See Also
    --------
    deregister_matplotlib_converters
    """
    # Renamed in pandas.plotting.__init__
    for type_, cls in get_pairs():
        # We use type to catch our classes directly, no inheritance
        if type(units.registry.get(type_)) is cls:
            units.registry.pop(type_)

    # restore the old keys
    for unit, formatter in _mpl_units.items():
        if type(formatter) not in {DatetimeConverter, PeriodConverter,
                                   TimeConverter}:
            # make it idempotent by excluding ours.
            units.registry[unit] = formatter 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:29,代码来源:_converter.py

示例4: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register(explicit=True):
    """Register Pandas Formatters and Converters with matplotlib

    This function modifies the global ``matplotlib.units.registry``
    dictionary. Pandas adds custom converters for

    * pd.Timestamp
    * pd.Period
    * np.datetime64
    * datetime.datetime
    * datetime.date
    * datetime.time

    See Also
    --------
    deregister_matplotlib_converter
    """
    # Renamed in pandas.plotting.__init__
    global _WARN

    if explicit:
        _WARN = False

    pairs = get_pairs()
    for type_, cls in pairs:
        converter = cls()
        if type_ in units.registry:
            previous = units.registry[type_]
            _mpl_units[type_] = previous
        units.registry[type_] = converter 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:32,代码来源:_converter.py

示例5: deregister

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def deregister():
    """Remove pandas' formatters and converters

    Removes the custom converters added by :func:`register`. This
    attempts to set the state of the registry back to the state before
    pandas registered its own units. Converters for pandas' own types like
    Timestamp and Period are removed completely. Converters for types
    pandas overwrites, like ``datetime.datetime``, are restored to their
    original value.

    See Also
    --------
    deregister_matplotlib_converters
    """
    # Renamed in pandas.plotting.__init__
    for type_, cls in get_pairs():
        # We use type to catch our classes directly, no inheritance
        if type(units.registry.get(type_)) is cls:
            units.registry.pop(type_)

    # restore the old keys
    for unit, formatter in _mpl_units.items():
        if type(formatter) not in {DatetimeConverter, PeriodConverter,
                                   TimeConverter}:
            # make it idempotent by excluding ours.
            units.registry[unit] = formatter 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:28,代码来源:_converter.py

示例6: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register():
    units.registry[lib.Timestamp] = DatetimeConverter()
    units.registry[Period] = PeriodConverter()
    units.registry[pydt.datetime] = DatetimeConverter()
    units.registry[pydt.date] = DatetimeConverter()
    units.registry[pydt.time] = TimeConverter() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:converter.py

示例7: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register():
   """Register the unit conversion classes with matplotlib."""
   import matplotlib.units as mplU

   mplU.registry[ str ] = StrConverter()
   mplU.registry[ Epoch ] = EpochConverter()
   mplU.registry[ UnitDbl ] = UnitDblConverter()

#=======================================================================
# Some default unit instances

# Distances 
开发者ID:Solid-Mechanics,项目名称:matplotlib-4-abaqus,代码行数:14,代码来源:__init__.py

示例8: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register():
    """Register the unit conversion classes with matplotlib."""
    import matplotlib.units as mplU

    mplU.registry[str] = StrConverter()
    mplU.registry[Epoch] = EpochConverter()
    mplU.registry[Duration] = EpochConverter()
    mplU.registry[UnitDbl] = UnitDblConverter()

# ======================================================================
# Some default unit instances


# Distances 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:__init__.py

示例9: __new__

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def __new__(cls, value, unit):
        # generate a new subclass for value
        value_class = type(value)
        try:
            subcls = type('TaggedValue_of_%s' % (value_class.__name__),
                          tuple([cls, value_class]),
                          {})
            if subcls not in units.registry:
                units.registry[subcls] = basicConverter
            return object.__new__(subcls)
        except TypeError:
            if cls not in units.registry:
                units.registry[cls] = basicConverter
            return object.__new__(cls) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:16,代码来源:basic_units.py

示例10: test_empty_set_limits_with_units

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def test_empty_set_limits_with_units(quantity_converter):
    # Register the class
    munits.registry[Quantity] = quantity_converter

    fig, ax = plt.subplots()
    ax.set_xlim(Quantity(-1, 'meters'), Quantity(6, 'meters'))
    ax.set_ylim(Quantity(-1, 'hours'), Quantity(16, 'hours')) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:9,代码来源:test_units.py

示例11: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register():
    units.registry[lib.Timestamp] = DatetimeConverter()
    units.registry[Period] = PeriodConverter()
    units.registry[pydt.datetime] = DatetimeConverter()
    units.registry[pydt.date] = DatetimeConverter()
    units.registry[pydt.time] = TimeConverter()
    units.registry[np.datetime64] = DatetimeConverter() 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:9,代码来源:_converter.py

示例12: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register():
    """Register the unit conversion classes with matplotlib."""
    import matplotlib.units as mplU

    mplU.registry[str] = StrConverter()
    mplU.registry[Epoch] = EpochConverter()
    mplU.registry[Duration] = EpochConverter()
    mplU.registry[UnitDbl] = UnitDblConverter()


# Some default unit instances
# Distances 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:14,代码来源:__init__.py

示例13: register

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def register():
   """Register the unit conversion classes with matplotlib."""
   import matplotlib.units as mplU

   mplU.registry[ str ] = StrConverter()
   mplU.registry[ Epoch ] = EpochConverter()
   mplU.registry[ Duration ] = EpochConverter()
   mplU.registry[ UnitDbl ] = UnitDblConverter()

#=======================================================================
# Some default unit instances

# Distances 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:15,代码来源:__init__.py

示例14: test_numpy_facade

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import registry [as 别名]
def test_numpy_facade():
    # Create an instance of the conversion interface and
    # mock so we can check methods called
    qc = munits.ConversionInterface()

    def convert(value, unit, axis):
        if hasattr(value, 'units'):
            return value.to(unit).magnitude
        elif iterable(value):
            try:
                return [v.to(unit).magnitude for v in value]
            except AttributeError:
                return [Quantity(v, axis.get_units()).to(unit).magnitude
                        for v in value]
        else:
            return Quantity(value, axis.get_units()).to(unit).magnitude

    qc.convert = MagicMock(side_effect=convert)
    qc.axisinfo = MagicMock(side_effect=lambda u, a: munits.AxisInfo(label=u))
    qc.default_units = MagicMock(side_effect=lambda x, a: x.units)

    # Register the class
    munits.registry[Quantity] = qc

    # Simple test
    y = Quantity(np.linspace(0, 30), 'miles')
    x = Quantity(np.linspace(0, 5), 'hours')

    fig, ax = plt.subplots()
    fig.subplots_adjust(left=0.15)  # Make space for label
    ax.plot(x, y, 'tab:blue')
    ax.axhline(Quantity(26400, 'feet'), color='tab:red')
    ax.axvline(Quantity(120, 'minutes'), color='tab:green')
    ax.yaxis.set_units('inches')
    ax.xaxis.set_units('seconds')

    assert qc.convert.called
    assert qc.axisinfo.called
    assert qc.default_units.called


# Tests gh-8908 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:44,代码来源:test_units.py


注:本文中的matplotlib.units.registry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。