Python matplotlib.units.registry() Examples
The following are 27
code examples of matplotlib.units.registry().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.units
, or try the search function
.
Example #1
Source File: test_units.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #2
Source File: test_units.py From coffeegrindsize with MIT License | 6 votes |
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
Example #3
Source File: _converter.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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
Example #4
Source File: _converter.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #5
Source File: _converter.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #6
Source File: __init__.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #7
Source File: __init__.py From CogAlg with MIT License | 5 votes |
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
Example #8
Source File: _converter.py From coffeegrindsize with MIT License | 5 votes |
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
Example #9
Source File: _converter.py From coffeegrindsize with MIT License | 5 votes |
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
Example #10
Source File: __init__.py From coffeegrindsize with MIT License | 5 votes |
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
Example #11
Source File: test_units.py From coffeegrindsize with MIT License | 5 votes |
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'))
Example #12
Source File: _converter.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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()
Example #13
Source File: _converter.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #14
Source File: _converter.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #15
Source File: _converter.py From recruit with Apache License 2.0 | 5 votes |
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
Example #16
Source File: _converter.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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
Example #17
Source File: __init__.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #18
Source File: test_units.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'))
Example #19
Source File: basic_units.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #20
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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
Example #21
Source File: __init__.py From neural-network-animation with MIT License | 5 votes |
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
Example #22
Source File: __init__.py From matplotlib-4-abaqus with MIT License | 5 votes |
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
Example #23
Source File: converter.py From Computable with MIT License | 5 votes |
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()
Example #24
Source File: _converter.py From vnpy_crypto with MIT License | 5 votes |
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
Example #25
Source File: _converter.py From vnpy_crypto with MIT License | 5 votes |
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
Example #26
Source File: _converter.py From recruit with Apache License 2.0 | 5 votes |
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
Example #27
Source File: test_units.py From twitter-stock-recommendation with MIT License | 4 votes |
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