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


Python units.ConversionInterface方法代码示例

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


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

示例1: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """
        If *value* is not already a number or sequence of numbers,
        convert it with :func:`date2num`.

        The *unit* and *axis* arguments are not used.
        """
        if units.ConversionInterface.is_numlike(value):
            return value
        return date2num(value) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:dates.py

示例2: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """Convert strings in value to floats using
        mapping information store in the unit object.

        Parameters
        ----------
        value : string or iterable
            Value or list of values to be converted.
        unit : `.UnitData`
            An object mapping strings to integers.
        axis : `~matplotlib.axis.Axis`
            axis on which the converted value is plotted.

            .. note:: *axis* is unused.

        Returns
        -------
        mapped_value : float or ndarray[float]
        """
        if unit is None:
            raise ValueError(
                'Missing category information for StrCategoryConverter; '
                'this might be caused by unintendedly mixing categorical and '
                'numeric data')

        # dtype = object preserves numerical pass throughs
        values = np.atleast_1d(np.array(value, dtype=object))

        # pass through sequence of non binary numbers
        if all((units.ConversionInterface.is_numlike(v) and
                not isinstance(v, (str, bytes))) for v in values):
            return np.asarray(values, dtype=float)

        # force an update so it also does type checking
        unit.update(values)

        str2idx = np.vectorize(unit._mapping.__getitem__,
                               otypes=[float])

        mapped_value = str2idx(values)
        return mapped_value 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:43,代码来源:category.py

示例3: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert( value, unit, axis ):
      """: Convert value using unit to a float.  If value is a sequence, return
      the converted sequence.

      = INPUT VARIABLES
      - value   The value or list of values that need to be converted.
      - unit    The units to use for an axis with Epoch data.

      = RETURN VALUE
      - Returns the value parameter converted to floats.
      """
      # Delay-load due to circular dependencies.
      import matplotlib.testing.jpl_units as U

      isNotEpoch = True
      isDuration = False

      if ( iterable(value) and not isinstance(value, str) ):
         if ( len(value) == 0 ):
            return []
         else:
            return [ EpochConverter.convert( x, unit, axis ) for x in value ]

      if ( isinstance(value, U.Epoch) ):
         isNotEpoch = False
      elif ( isinstance(value, U.Duration) ):
         isDuration = True

      if ( isNotEpoch and not isDuration and
           units.ConversionInterface.is_numlike( value ) ):
         return value

      if ( unit == None ):
         unit = EpochConverter.default_units( value, axis )

      if ( isDuration ):
         return EpochConverter.duration2float( value )
      else:
         return EpochConverter.epoch2float( value, unit )

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

示例4: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert( value, unit, axis ):
      """: Convert value using unit to a float.  If value is a sequence, return
      the converted sequence.

      = INPUT VARIABLES
      - value   The value or list of values that need to be converted.
      - unit    The units to use for an axis with Epoch data.

      = RETURN VALUE
      - Returns the value parameter converted to floats.
      """
      # Delay-load due to circular dependencies.
      import matplotlib.testing.jpl_units as U

      isNotEpoch = True
      isDuration = False

      if ( iterable(value) and not isinstance(value, six.string_types) ):
         if ( len(value) == 0 ):
            return []
         else:
            return [ EpochConverter.convert( x, unit, axis ) for x in value ]

      if ( isinstance(value, U.Epoch) ):
         isNotEpoch = False
      elif ( isinstance(value, U.Duration) ):
         isDuration = True

      if ( isNotEpoch and not isDuration and
           units.ConversionInterface.is_numlike( value ) ):
         return value

      if ( unit == None ):
         unit = EpochConverter.default_units( value, axis )

      if ( isDuration ):
         return EpochConverter.duration2float( value )
      else:
         return EpochConverter.epoch2float( value, unit )

   #------------------------------------------------------------------------ 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:43,代码来源:EpochConverter.py

示例5: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """Converts strings in value to floats using
        mapping information store in the unit object.

        Parameters
        ----------
        value : string or iterable
            value or list of values to be converted
        unit : :class:`.UnitData`
           object string unit information for value
        axis : :class:`~matplotlib.Axis.axis`
            axis on which the converted value is plotted

        Returns
        -------
        mapped_ value : float or ndarray[float]

        .. note:: axis is not used in this function
        """
        # dtype = object preserves numerical pass throughs
        values = np.atleast_1d(np.array(value, dtype=object))

        # pass through sequence of non binary numbers
        if all((units.ConversionInterface.is_numlike(v) and
                not isinstance(v, (str, bytes))) for v in values):
            return np.asarray(values, dtype=float)

        # force an update so it also does type checking
        unit.update(values)

        str2idx = np.vectorize(unit._mapping.__getitem__,
                               otypes=[float])

        mapped_value = str2idx(values)
        return mapped_value 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:37,代码来源:category.py

示例6: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """: Convert value using unit to a float.  If value is a sequence, return
        the converted sequence.

        = INPUT VARIABLES
        - value    The value or list of values that need to be converted.
        - unit     The units to use for an axis with Epoch data.

        = RETURN VALUE
        - Returns the value parameter converted to floats.
        """
        # Delay-load due to circular dependencies.
        import matplotlib.testing.jpl_units as U

        isNotEpoch = True
        isDuration = False

        if iterable(value) and not isinstance(value, str):
            if len(value) == 0:
                return []
            else:
                return [EpochConverter.convert(x, unit, axis) for x in value]

        if isinstance(value, U.Epoch):
            isNotEpoch = False
        elif isinstance(value, U.Duration):
            isDuration = True

        if (isNotEpoch and not isDuration and
           units.ConversionInterface.is_numlike(value)):
            return value

        if unit is None:
            unit = EpochConverter.default_units(value, axis)

        if isDuration:
            return EpochConverter.duration2float(value)
        else:
            return EpochConverter.epoch2float(value, unit)

    # ----------------------------------------------------------------------- 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:43,代码来源:EpochConverter.py

示例7: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(val, unit, axis):
        if units.ConversionInterface.is_numlike(val):
            return val
        if iterable(val):
            return [thisval.convert_to(unit).get_value() for thisval in val]
        else:
            return val.convert_to(unit).get_value() 
开发者ID:holzschu,项目名称:python3_ios,代码行数:9,代码来源:basic_units.py

示例8: quantity_converter

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def quantity_converter():
    # 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

    def default_units(value, axis):
        if hasattr(value, 'units'):
            return value.units
        elif np.iterable(value):
            for v in value:
                if hasattr(v, 'units'):
                    return v.units
            return None

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


# Tests that the conversion machinery works properly for classes that
# work as a facade over numpy arrays (like pint) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:36,代码来源:test_units.py

示例9: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """: Convert value using unit to a float.  If value is a sequence, return
        the converted sequence.

        = INPUT VARIABLES
        - value    The value or list of values that need to be converted.
        - unit     The units to use for an axis with Epoch data.

        = RETURN VALUE
        - Returns the value parameter converted to floats.
        """
        # Delay-load due to circular dependencies.
        import matplotlib.testing.jpl_units as U

        isNotEpoch = True
        isDuration = False

        if np.iterable(value) and not isinstance(value, str):
            if len(value) == 0:
                return []
            else:
                return [EpochConverter.convert(x, unit, axis) for x in value]

        if isinstance(value, U.Epoch):
            isNotEpoch = False
        elif isinstance(value, U.Duration):
            isDuration = True

        if (isNotEpoch and not isDuration and
           units.ConversionInterface.is_numlike(value)):
            return value

        if unit is None:
            unit = EpochConverter.default_units(value, axis)

        if isDuration:
            return EpochConverter.duration2float(value)
        else:
            return EpochConverter.epoch2float(value, unit) 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:41,代码来源:EpochConverter.py

示例10: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """Converts strings in value to floats using
        mapping information store in the  unit object

        Parameters
        ----------
        value : string or iterable
            value or list of values to be converted
        unit : :class:`.UnitData`
           object string unit information for value
        axis : :class:`~matplotlib.Axis.axis`
            axis on which the converted value is plotted

        Returns
        -------
        mapped_ value : float or ndarray[float]

        .. note:: axis is not used in this function
        """
        # dtype = object preserves numerical pass throughs
        values = np.atleast_1d(np.array(value, dtype=object))

        # pass through sequence of non binary numbers
        if all((units.ConversionInterface.is_numlike(v) and
                not isinstance(v, VALID_TYPES)) for v in values):
            return np.asarray(values, dtype=float)

        # force an update so it also does type checking
        unit.update(values)

        str2idx = np.vectorize(unit._mapping.__getitem__,
                               otypes=[float])

        mapped_value = str2idx(values)
        return mapped_value 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:37,代码来源:category.py

示例11: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert( value, unit, axis ):
      """: Convert value using unit to a float.  If value is a sequence, return
      the converted sequence.

      = INPUT VARIABLES
      - value   The value or list of values that need to be converted.
      - unit    The units to use for a axis with Epoch data.

      = RETURN VALUE
      - Returns the value parameter converted to floats.
      """
      # Delay-load due to circular dependencies.
      import matplotlib.testing.jpl_units as U

      isNotUnitDbl = True

      if ( iterable(value) and not isinstance(value, str) ):
         if ( len(value) == 0 ):
            return []
         else:
            return [ UnitDblConverter.convert( x, unit, axis ) for x in value ]

      # We need to check to see if the incoming value is actually a UnitDbl and
      # set a flag.  If we get an empty list, then just return an empty list.
      if ( isinstance(value, U.UnitDbl) ):
         isNotUnitDbl = False

      # If the incoming value behaves like a number, but is not a UnitDbl,
      # then just return it because we don't know how to convert it
      # (or it is already converted)
      if ( isNotUnitDbl and units.ConversionInterface.is_numlike( value ) ):
         return value

      # If no units were specified, then get the default units to use.
      if ( unit == None ):
         unit = UnitDblConverter.default_units( value, axis )

      # Convert the incoming UnitDbl value/values to float/floats
      if isinstance( axis.axes, polar.PolarAxes ) and (value.type() == "angle"):
         # Guarantee that units are radians for polar plots.
         return value.convert( "rad" )

      return value.convert( unit )

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

示例12: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert( value, unit, axis ):
      """: Convert value using unit to a float.  If value is a sequence, return
      the converted sequence.

      = INPUT VARIABLES
      - value   The value or list of values that need to be converted.
      - unit    The units to use for a axis with Epoch data.

      = RETURN VALUE
      - Returns the value parameter converted to floats.
      """
      # Delay-load due to circular dependencies.
      import matplotlib.testing.jpl_units as U

      isNotUnitDbl = True

      if ( iterable(value) and not isinstance(value, six.string_types) ):
         if ( len(value) == 0 ):
            return []
         else:
            return [ UnitDblConverter.convert( x, unit, axis ) for x in value ]

      # We need to check to see if the incoming value is actually a UnitDbl and
      # set a flag.  If we get an empty list, then just return an empty list.
      if ( isinstance(value, U.UnitDbl) ):
         isNotUnitDbl = False

      # If the incoming value behaves like a number, but is not a UnitDbl,
      # then just return it because we don't know how to convert it
      # (or it is already converted)
      if ( isNotUnitDbl and units.ConversionInterface.is_numlike( value ) ):
         return value

      # If no units were specified, then get the default units to use.
      if ( unit == None ):
         unit = UnitDblConverter.default_units( value, axis )

      # Convert the incoming UnitDbl value/values to float/floats
      if isinstance( axis.axes, polar.PolarAxes ) and (value.type() == "angle"):
         # Guarantee that units are radians for polar plots.
         return value.convert( "rad" )

      return value.convert( unit )

   #------------------------------------------------------------------------ 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:47,代码来源:UnitDblConverter.py

示例13: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """: Convert value using unit to a float.  If value is a sequence, return
        the converted sequence.

        = INPUT VARIABLES
        - value    The value or list of values that need to be converted.
        - unit     The units to use for a axis with Epoch data.

        = RETURN VALUE
        - Returns the value parameter converted to floats.
        """
        # Delay-load due to circular dependencies.
        import matplotlib.testing.jpl_units as U

        isNotUnitDbl = True

        if iterable(value) and not isinstance(value, str):
            if len(value) == 0:
                return []
            else:
                return [UnitDblConverter.convert(x, unit, axis) for x in value]

        # We need to check to see if the incoming value is actually a
        # UnitDbl and set a flag.  If we get an empty list, then just
        # return an empty list.
        if (isinstance(value, U.UnitDbl)):
            isNotUnitDbl = False

        # If the incoming value behaves like a number, but is not a UnitDbl,
        # then just return it because we don't know how to convert it
        # (or it is already converted)
        if (isNotUnitDbl and units.ConversionInterface.is_numlike(value)):
            return value

        # If no units were specified, then get the default units to use.
        if unit is None:
            unit = UnitDblConverter.default_units(value, axis)

        # Convert the incoming UnitDbl value/values to float/floats
        if isinstance(axis.axes, polar.PolarAxes) and value.type() == "angle":
            # Guarantee that units are radians for polar plots.
            return value.convert("rad")

        return value.convert(unit)

    # ----------------------------------------------------------------------- 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:48,代码来源:UnitDblConverter.py

示例14: convert

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [as 别名]
def convert(value, unit, axis):
        """: Convert value using unit to a float.  If value is a sequence, return
        the converted sequence.

        = INPUT VARIABLES
        - value    The value or list of values that need to be converted.
        - unit     The units to use for a axis with Epoch data.

        = RETURN VALUE
        - Returns the value parameter converted to floats.
        """
        # Delay-load due to circular dependencies.
        import matplotlib.testing.jpl_units as U

        isNotUnitDbl = True

        if np.iterable(value) and not isinstance(value, str):
            if len(value) == 0:
                return []
            else:
                return [UnitDblConverter.convert(x, unit, axis) for x in value]

        # We need to check to see if the incoming value is actually a
        # UnitDbl and set a flag.  If we get an empty list, then just
        # return an empty list.
        if isinstance(value, U.UnitDbl):
            isNotUnitDbl = False

        # If the incoming value behaves like a number, but is not a UnitDbl,
        # then just return it because we don't know how to convert it
        # (or it is already converted)
        if isNotUnitDbl and units.ConversionInterface.is_numlike(value):
            return value

        # If no units were specified, then get the default units to use.
        if unit is None:
            unit = UnitDblConverter.default_units(value, axis)

        # Convert the incoming UnitDbl value/values to float/floats
        if isinstance(axis.axes, polar.PolarAxes) and value.type() == "angle":
            # Guarantee that units are radians for polar plots.
            return value.convert("rad")

        return value.convert(unit) 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:46,代码来源:UnitDblConverter.py

示例15: test_numpy_facade

# 需要导入模块: from matplotlib import units [as 别名]
# 或者: from matplotlib.units import ConversionInterface [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.ConversionInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。