From 6e50a75e0929c975aefd5e74e08fbce65df8ebf9 Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 13:21:04 -0600 Subject: [PATCH 01/14] update covert to handle sequences and make the interface optional --- unyt/__init__.py | 2 +- unyt/mpl_interface.py | 39 ++++++++++++++++++++++++---- unyt/tests/test_mpl_interface.py | 44 +++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/unyt/__init__.py b/unyt/__init__.py index f8989964..e3720101 100644 --- a/unyt/__init__.py +++ b/unyt/__init__.py @@ -96,7 +96,7 @@ from unyt.unit_systems import UnitSystem # NOQA: F401 from unyt.testing import assert_allclose_units # NOQA: F401 from unyt.dimensions import accepts, returns # NOQA: F401 -from unyt import mpl_interface # NOQA: F401 +from unyt.mpl_interface import MplUnitsCM # NOQA: F401 # function to only import quantities into this namespace diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index 8d055910..1c2ad466 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -18,6 +18,7 @@ ConversionInterface, AxisInfo, registry, + ConversionError, ) except ImportError: pass @@ -81,7 +82,7 @@ def convert(value, unit, axis): Parameters ---------- - value : unyt_array + value : unyt_array, unyt_quantity, or sequence there of unit : Unit, string or tuple This parameter comes from unyt_arrayConverter.default_units() or from user code such as Axes.plot(), Axis.set_units(), etc. In user code, it @@ -98,11 +99,39 @@ def convert(value, unit, axis): Raises ------ - ConversionError if unit does not have the same dimensions as value + ConversionError if unit does not have the same dimensions as value or + if we don't know how to convert value. """ if isinstance(unit, str) or isinstance(unit, Unit): unit = (unit,) - return value.to(*unit) + if isinstance(value, (unyt_array, unyt_quantity)): + converted_value = value.to(*unit) + elif isinstance(value, (list, tuple)): + value_type = type(value) + converted_value = [] + for obj in value: + converted_value.append(obj.to(*unit)) + converted_value = value_type(converted_value) + else: + raise ConversionError(f"unable to convert {value}") + return converted_value + + class MplUnitsCM: + """Context manager for experimenting with Unyt in Matplotlib""" + + def __enter__(self): + registry[unyt_array] = unyt_arrayConverter() + registry[unyt_quantity] = unyt_arrayConverter() + + def __exit__(self, exc_type, exc_val, exc_tb): + registry.pop(unyt_array) + registry.pop(unyt_quantity) + + def enable(self): + self.__enter__() + + def disable(self): + self.__exit__() - registry[unyt_array] = unyt_arrayConverter() - registry[unyt_quantity] = unyt_arrayConverter() + def __repr__(self): + return "" diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index 94cb6cb2..c975fe91 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -2,8 +2,9 @@ import numpy as np import pytest from unyt._on_demand_imports import _matplotlib, NotAModule -from unyt import s, K +from unyt import s, K, unyt_array, unyt_quantity from unyt.exceptions import UnitConversionError +from unyt.mpl_interface import MplUnitsCM check_matplotlib = pytest.mark.skipif( @@ -13,9 +14,12 @@ @pytest.fixture def ax(scope="module"): + mpl_units = MplUnitsCM() + mpl_units.enable() fig, ax = _matplotlib.pyplot.subplots() yield ax _matplotlib.pyplot.close() + mpl_units.disable() @check_matplotlib @@ -101,3 +105,41 @@ def test_list_label(ax): assert ax.xaxis.get_label().get_text() == expected_xlabel expected_ylabel = "" assert ax.yaxis.get_label().get_text() == expected_ylabel + + +@check_matplotlib +def test_errorbar(ax): + x = unyt_array([8, 9, 10], "cm") + y = unyt_array([8, 9, 10], "kg") + y_scatter = [ + unyt_array([0.1, 0.2, 0.3], "kg"), + unyt_array([0.1, 0.2, 0.3], "kg"), + ] + x_lims = (unyt_quantity(5, "cm"), unyt_quantity(12, "cm")) + y_lims = (unyt_quantity(5, "kg"), unyt_quantity(12, "kg")) + + ax.errorbar(x, y, yerr=y_scatter) + x_lims = (unyt_quantity(5, "cm"), unyt_quantity(12, "cm")) + y_lims = (unyt_quantity(5, "kg"), unyt_quantity(12, "kg")) + ax.set_xlim(*x_lims) + ax.set_ylim(*y_lims) + + +@check_matplotlib +def test_hist2d(ax): + x = np.random.normal(size=50000) * s + y = 3 * x + np.random.normal(size=50000) * s + ax.hist2d(x, y, bins=(50, 50)) + + +@check_matplotlib +def test_imshow(ax): + data = np.reshape(np.random.normal(size=10000), (100, 100)) + ax.imshow(data, vmin=data.min(), vmax=data.max()) + + +@check_matplotlib +def test_hist(ax): + data = np.random.normal(size=10000) * s + bin_edges = np.linspace(data.min(), data.max(), 50) + ax.hist(data, bins=bin_edges) From 12472f8ccdfd4a251a6bdf451674a8f292bbaf18 Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 13:52:26 -0600 Subject: [PATCH 02/14] update documentation and add context manager test --- docs/usage.rst | 17 ++++++++++------- unyt/mpl_interface.py | 2 +- unyt/tests/test_mpl_interface.py | 14 +++++++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index b9ae7b6c..9efe05bf 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1184,25 +1184,28 @@ calculation involves many operations on arrays with only a few elements. Plotting with Matplotlib ++++++++++++++++++++++++ +.. note:: + - This is an experimental feature. Please report issues. + - The context manager ``MplUnitsCM`` will temporarily enable this feature Matplotlib is Unyt aware. With no additional effort, Matplotlib will label the x and y axes with the units. >>> import matplotlib.pyplot as plt - >>> from unyt import s, K + >>> from unyt import s, K, MplUnitsCM >>> x = [0.0, 0.01, 0.02]*s >>> y = [298.15, 308.15, 318.15]*K - >>> plt.plot(x, y) - [] - >>> plt.show() + >>> with MplUnitsCM(): + ... plt.plot(x, y) + ... plt.show() .. image:: _static/mpl_fig1.png You can change the plotted units without affecting the original data. - >>> plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) - [] - >>> plt.show() + >>> with MplUnitsCM(): + ... plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) + ... plt.show() .. image:: _static/mpl_fig2.png diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index 1c2ad466..7e50c65a 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -131,7 +131,7 @@ def enable(self): self.__enter__() def disable(self): - self.__exit__() + self.__exit__(None, None, None) def __repr__(self): return "" diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index c975fe91..fa40235a 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -4,7 +4,7 @@ from unyt._on_demand_imports import _matplotlib, NotAModule from unyt import s, K, unyt_array, unyt_quantity from unyt.exceptions import UnitConversionError -from unyt.mpl_interface import MplUnitsCM +from unyt.mpl_interface import MplUnitsCM, unyt_arrayConverter check_matplotlib = pytest.mark.skipif( @@ -143,3 +143,15 @@ def test_hist(ax): data = np.random.normal(size=10000) * s bin_edges = np.linspace(data.min(), data.max(), 50) ax.hist(data, bins=bin_edges) + + +@check_matplotlib +def test_MplUnitsCM(): + mplunits = MplUnitsCM() + with pytest.raises(KeyError): + _matplotlib.units.registry[unyt_array] + mplunits.enable() + assert isinstance(_matplotlib.units.registry[unyt_array], unyt_arrayConverter) + mplunits.disable() + assert unyt_array not in _matplotlib.units.registry.keys() + assert unyt_quantity not in _matplotlib.units.registry.keys() From 031fa5c30fe82e650b827888286dc9a53129a0ff Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 14:04:57 -0600 Subject: [PATCH 03/14] fix usage doctest --- docs/usage.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 9efe05bf..995c50ce 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1196,16 +1196,16 @@ axes with the units. >>> x = [0.0, 0.01, 0.02]*s >>> y = [298.15, 308.15, 318.15]*K >>> with MplUnitsCM(): - ... plt.plot(x, y) - ... plt.show() + plt.plot(x, y) + plt.show() .. image:: _static/mpl_fig1.png You can change the plotted units without affecting the original data. >>> with MplUnitsCM(): - ... plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) - ... plt.show() + plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) + plt.show() .. image:: _static/mpl_fig2.png From 972cb4bba6e09eea2527846a4ca6ebe30297c3ff Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 14:33:00 -0600 Subject: [PATCH 04/14] fix doctest in usage --- docs/usage.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 995c50ce..f328ff7c 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1196,16 +1196,18 @@ axes with the units. >>> x = [0.0, 0.01, 0.02]*s >>> y = [298.15, 308.15, 318.15]*K >>> with MplUnitsCM(): - plt.plot(x, y) - plt.show() + ... plt.plot(x, y) + ... plt.show() + [] .. image:: _static/mpl_fig1.png You can change the plotted units without affecting the original data. >>> with MplUnitsCM(): - plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) - plt.show() + ... plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) + ... plt.show() + [] .. image:: _static/mpl_fig2.png From c56bb7b42cabd7940f321275278a550392ada292 Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 17:15:26 -0600 Subject: [PATCH 05/14] make context manager callable, update docs and tests --- docs/usage.rst | 8 ++--- unyt/__init__.py | 4 ++- unyt/mpl_interface.py | 59 +++++++++++++++++++++++++++++--- unyt/tests/test_mpl_interface.py | 42 ++++++++++++++++++----- 4 files changed, 95 insertions(+), 18 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index f328ff7c..faa877de 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1186,16 +1186,16 @@ Plotting with Matplotlib ++++++++++++++++++++++++ .. note:: - This is an experimental feature. Please report issues. - - The context manager ``MplUnitsCM`` will temporarily enable this feature + - The context manager ``matplotlib_support`` will temporarily enable this feature Matplotlib is Unyt aware. With no additional effort, Matplotlib will label the x and y axes with the units. >>> import matplotlib.pyplot as plt - >>> from unyt import s, K, MplUnitsCM + >>> from unyt import s, K, matplotlib_support >>> x = [0.0, 0.01, 0.02]*s >>> y = [298.15, 308.15, 318.15]*K - >>> with MplUnitsCM(): + >>> with matplotlib_support: ... plt.plot(x, y) ... plt.show() [] @@ -1204,7 +1204,7 @@ axes with the units. You can change the plotted units without affecting the original data. - >>> with MplUnitsCM(): + >>> with matplotlib_support: ... plt.plot(x, y, xunits="ms", yunits=("J", "thermal")) ... plt.show() [] diff --git a/unyt/__init__.py b/unyt/__init__.py index e3720101..dcc63318 100644 --- a/unyt/__init__.py +++ b/unyt/__init__.py @@ -96,7 +96,9 @@ from unyt.unit_systems import UnitSystem # NOQA: F401 from unyt.testing import assert_allclose_units # NOQA: F401 from unyt.dimensions import accepts, returns # NOQA: F401 -from unyt.mpl_interface import MplUnitsCM # NOQA: F401 +from unyt.mpl_interface import matplotlib_support # NOQA: F401 + +matplotlib_support = matplotlib_support() # function to only import quantities into this namespace diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index 7e50c65a..2629f769 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -28,6 +28,8 @@ class unyt_arrayConverter(ConversionInterface): """Matplotlib interface for unyt_array""" + _labelstyle = "()" + @staticmethod def axisinfo(unit, axis): """Set the axis label based on unit @@ -55,7 +57,18 @@ def axisinfo(unit, axis): label = "" else: unit_str = unit_obj.latex_representation() - label = "$\\left(" + unit_str + "\\right)$" + if unyt_arrayConverter._labelstyle == "[]": + label = "$\\left[" + unit_str + "\\right]$" + elif unyt_arrayConverter._labelstyle == "/": + axsym = axis.axis_name + if "/" in unit_str: + label = ( + "$q_{" + axsym + "}\\;/\\;\\left(" + unit_str + "\\right)$" + ) + else: + label = "$q_{" + axsym + "}\\;/\\;" + unit_str + "$" + else: + label = "$\\left(" + unit_str + "\\right)$" return AxisInfo(label=label) @staticmethod @@ -113,11 +126,49 @@ def convert(value, unit, axis): converted_value.append(obj.to(*unit)) converted_value = value_type(converted_value) else: - raise ConversionError(f"unable to convert {value}") + raise ConversionError("unable to convert {%s}".format(value)) return converted_value - class MplUnitsCM: - """Context manager for experimenting with Unyt in Matplotlib""" + class matplotlib_support: + """Context manager for experimenting with Unyt in Matplotlib + + Parameters + ---------- + + label_style : string, one from the set {'()', '[]', '/'} + The axis label style. + '()' -> '(unit)' + '[]' -> '[unit]' + '/' -> 'q / unit' + SI standard where label is a mathematical expression. + 'q' is a generic quantity symbol and for a value on the axis, x, + the equation is q = x * unit. + """ + + def __init__(self, label_style="()"): + self._labelstyle = label_style + unyt_arrayConverter._labelstyle = label_style + + def __call__(self): + self.__enter__() + + @property + def label_style(self): + """label_style : string, one from the set {'()', '[]', '/'} + The axis label style. + '()' -> '(unit)' + '[]' -> '[unit]' + '/' -> 'q / unit' + SI standard where label is a mathematical expression. + 'q' is a generic quantity symbol and for a value on the axis, x, + the equation is q = x * unit. + """ + return self._labelstyle + + @label_style.setter + def label_style(self, label_style="()"): + self._labelstyle = label_style + unyt_arrayConverter._labelstyle = label_style def __enter__(self): registry[unyt_array] = unyt_arrayConverter() diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index fa40235a..39f182d7 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -2,9 +2,9 @@ import numpy as np import pytest from unyt._on_demand_imports import _matplotlib, NotAModule -from unyt import s, K, unyt_array, unyt_quantity +from unyt import s, K, unyt_array, unyt_quantity, matplotlib_support from unyt.exceptions import UnitConversionError -from unyt.mpl_interface import MplUnitsCM, unyt_arrayConverter +from unyt.mpl_interface import unyt_arrayConverter check_matplotlib = pytest.mark.skipif( @@ -14,12 +14,11 @@ @pytest.fixture def ax(scope="module"): - mpl_units = MplUnitsCM() - mpl_units.enable() + matplotlib_support.enable() fig, ax = _matplotlib.pyplot.subplots() yield ax _matplotlib.pyplot.close() - mpl_units.disable() + matplotlib_support.disable() @check_matplotlib @@ -146,12 +145,37 @@ def test_hist(ax): @check_matplotlib -def test_MplUnitsCM(): - mplunits = MplUnitsCM() +def test_matplotlib_support(): with pytest.raises(KeyError): _matplotlib.units.registry[unyt_array] - mplunits.enable() + matplotlib_support.enable() assert isinstance(_matplotlib.units.registry[unyt_array], unyt_arrayConverter) - mplunits.disable() + matplotlib_support.disable() assert unyt_array not in _matplotlib.units.registry.keys() assert unyt_quantity not in _matplotlib.units.registry.keys() + # test as a callable + matplotlib_support() + assert isinstance(_matplotlib.units.registry[unyt_array], unyt_arrayConverter) + + +@check_matplotlib +def test_labelstyle(): + x = [0, 1, 2] * s + y = [3, 4, 5] * K + matplotlib_support.label_style = "[]" + matplotlib_support.enable() + assert unyt_arrayConverter._labelstyle == "[]" + fig, ax = _matplotlib.pyplot.subplots() + ax.plot(x, y) + expected_xlabel = "$\\left[\\rm{s}\\right]$" + assert ax.xaxis.get_label().get_text() == expected_xlabel + expected_ylabel = "$\\left[\\rm{K}\\right]$" + assert ax.yaxis.get_label().get_text() == expected_ylabel + matplotlib_support.label_style = "/" + ax.clear() + ax.plot(x, y) + expected_xlabel = "$q_{x}\\;/\\;\\rm{s}$" + assert ax.xaxis.get_label().get_text() == expected_xlabel + expected_ylabel = "$q_{y}\\;/\\;\\rm{K}$" + assert ax.yaxis.get_label().get_text() == expected_ylabel + _matplotlib.pyplot.close() From 20287125503d9a5c48ee6dcf9d5f491ebd8585c9 Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 17:58:58 -0600 Subject: [PATCH 06/14] fix import issue when matplotlib isn't available --- unyt/__init__.py | 8 ++++++-- unyt/mpl_interface.py | 3 --- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/unyt/__init__.py b/unyt/__init__.py index dcc63318..a83476ab 100644 --- a/unyt/__init__.py +++ b/unyt/__init__.py @@ -96,9 +96,13 @@ from unyt.unit_systems import UnitSystem # NOQA: F401 from unyt.testing import assert_allclose_units # NOQA: F401 from unyt.dimensions import accepts, returns # NOQA: F401 -from unyt.mpl_interface import matplotlib_support # NOQA: F401 -matplotlib_support = matplotlib_support() +try: + from unyt.mpl_interface import matplotlib_support # NOQA: F401 +except ImportError: + pass +else: + matplotlib_support = matplotlib_support() # function to only import quantities into this namespace diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index 2629f769..3c8b37d9 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -183,6 +183,3 @@ def enable(self): def disable(self): self.__exit__(None, None, None) - - def __repr__(self): - return "" From 15609539bf135e6b7da96559f4507cc00d481c53 Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 18:42:53 -0600 Subject: [PATCH 07/14] fix import issue and add some more documentation --- docs/usage.rst | 30 ++++++++++++++++++++++++++++++ unyt/tests/test_mpl_interface.py | 8 ++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index faa877de..f57e5706 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1211,6 +1211,36 @@ You can change the plotted units without affecting the original data. .. image:: _static/mpl_fig2.png +There are three ways to use the context manager. + +1. As a conventional context manager in a ``with`` statement as shown above + +2. As a feature toggle in an interactive session + + >>> import matplotlib.pyplot as plt + >>> from unyt import s, K, matplotlib_support + >>> matplotlib_support.enable() + >>> plt.plot([0, 1, 2]*s, [3, 4, 5]*K) + [] + >>> plt.show() + >>> matplotlib_support.disable() + +3. As an enable for a complete session + + >>> import unyt + >>> unyt.matplotlib_support() + >>> import matplotlib.pyplot as plt + +It is possible to set the label style. + + >>> import matplotlib.pyplot as plt + >>> from unyt import s, K, matplotlib_support + >>> matplotlib_support.label_style = "[]" + >>> with matplotlib_support: + ... plt.plot([0, 1, 2]*s, [3, 4, 5]*K) + ... plt.show() + [] + .. note:: - This feature works in Matplotlib versions 2.2.4 and above diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index 39f182d7..7aee8a22 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -2,10 +2,14 @@ import numpy as np import pytest from unyt._on_demand_imports import _matplotlib, NotAModule -from unyt import s, K, unyt_array, unyt_quantity, matplotlib_support +from unyt import s, K, unyt_array, unyt_quantity from unyt.exceptions import UnitConversionError -from unyt.mpl_interface import unyt_arrayConverter +try: + from unyt import matplotlib_support + from unyt.mpl_interface import unyt_arrayConverter +except ImportError: + pass check_matplotlib = pytest.mark.skipif( isinstance(_matplotlib.pyplot, NotAModule), reason="matplotlib not installed" From e24853cede8cf4d9a20e90d31d44778f9b6dfcf1 Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 19:24:37 -0600 Subject: [PATCH 08/14] fix matplotlib 2.2.4 issues --- unyt/_on_demand_imports.py | 11 +++++++++++ unyt/mpl_interface.py | 4 ++-- unyt/tests/test_mpl_interface.py | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/unyt/_on_demand_imports.py b/unyt/_on_demand_imports.py index 0b09d8b3..fe6dd854 100644 --- a/unyt/_on_demand_imports.py +++ b/unyt/_on_demand_imports.py @@ -131,6 +131,7 @@ class matplotlib_imports(object): _name = "matplotlib" _pyplot = None _units = None + _use = None @property def __version__(self): @@ -163,5 +164,15 @@ def units(self): self._units = units return self._units + @property + def use(self): + if self._use is None: + try: + from matplotlib import use + except ImportError: + use = NotAModule(self._name) + self._use = use + return self._use + _matplotlib = matplotlib_imports() diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index 3c8b37d9..53b3d016 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -18,12 +18,12 @@ ConversionInterface, AxisInfo, registry, - ConversionError, ) except ImportError: pass else: from unyt import unyt_array, unyt_quantity, Unit + from unyt.exceptions import UnitConversionError class unyt_arrayConverter(ConversionInterface): """Matplotlib interface for unyt_array""" @@ -126,7 +126,7 @@ def convert(value, unit, axis): converted_value.append(obj.to(*unit)) converted_value = value_type(converted_value) else: - raise ConversionError("unable to convert {%s}".format(value)) + raise UnitConversionError("unable to convert {%s}".format(value)) return converted_value class matplotlib_support: diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index 7aee8a22..367ab67d 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -17,7 +17,8 @@ @pytest.fixture -def ax(scope="module"): +def ax(): + _matplotlib.use("agg") matplotlib_support.enable() fig, ax = _matplotlib.pyplot.subplots() yield ax From f1b5f3c6f07ec4d595ecc0c546e493a860f8610c Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 19:33:28 -0600 Subject: [PATCH 09/14] fix label_style test issue --- unyt/tests/test_mpl_interface.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index 367ab67d..6c55b6a2 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -30,6 +30,7 @@ def ax(): def test_label(ax): x = [0, 1, 2] * s y = [3, 4, 5] * K + matplotlib_support.label_style = "()" ax.plot(x, y) expected_xlabel = "$\\left(\\rm{s}\\right)$" assert ax.xaxis.get_label().get_text() == expected_xlabel @@ -93,6 +94,7 @@ def test_conversionerror(ax): def test_ndarray_label(ax): x = [0, 1, 2] * s y = np.arange(3, 6) + matplotlib_support.label_style = "()" ax.plot(x, y) expected_xlabel = "$\\left(\\rm{s}\\right)$" assert ax.xaxis.get_label().get_text() == expected_xlabel @@ -104,6 +106,7 @@ def test_ndarray_label(ax): def test_list_label(ax): x = [0, 1, 2] * s y = [3, 4, 5] + matplotlib_support.label_style = "()" ax.plot(x, y) expected_xlabel = "$\\left(\\rm{s}\\right)$" assert ax.xaxis.get_label().get_text() == expected_xlabel From 63b9902b4c571a4655f87a56f1438aa96f42d0ec Mon Sep 17 00:00:00 2001 From: Lee Johnston Date: Tue, 21 Jan 2020 20:24:27 -0600 Subject: [PATCH 10/14] increase code coverage --- unyt/mpl_interface.py | 9 +++------ unyt/tests/test_mpl_interface.py | 8 +++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index 53b3d016..d579cdaf 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -23,7 +23,6 @@ pass else: from unyt import unyt_array, unyt_quantity, Unit - from unyt.exceptions import UnitConversionError class unyt_arrayConverter(ConversionInterface): """Matplotlib interface for unyt_array""" @@ -112,21 +111,19 @@ def convert(value, unit, axis): Raises ------ - ConversionError if unit does not have the same dimensions as value or - if we don't know how to convert value. + ConversionError if unit does not have the same dimensions as value """ + converted_value = value if isinstance(unit, str) or isinstance(unit, Unit): unit = (unit,) if isinstance(value, (unyt_array, unyt_quantity)): converted_value = value.to(*unit) - elif isinstance(value, (list, tuple)): + else: value_type = type(value) converted_value = [] for obj in value: converted_value.append(obj.to(*unit)) converted_value = value_type(converted_value) - else: - raise UnitConversionError("unable to convert {%s}".format(value)) return converted_value class matplotlib_support: diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index 6c55b6a2..ace8b403 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -2,7 +2,7 @@ import numpy as np import pytest from unyt._on_demand_imports import _matplotlib, NotAModule -from unyt import s, K, unyt_array, unyt_quantity +from unyt import m, s, K, unyt_array, unyt_quantity from unyt.exceptions import UnitConversionError try: @@ -171,6 +171,7 @@ def test_labelstyle(): x = [0, 1, 2] * s y = [3, 4, 5] * K matplotlib_support.label_style = "[]" + assert matplotlib_support.label_style == "[]" matplotlib_support.enable() assert unyt_arrayConverter._labelstyle == "[]" fig, ax = _matplotlib.pyplot.subplots() @@ -186,4 +187,9 @@ def test_labelstyle(): assert ax.xaxis.get_label().get_text() == expected_xlabel expected_ylabel = "$q_{y}\\;/\\;\\rm{K}$" assert ax.yaxis.get_label().get_text() == expected_ylabel + x = [0, 1, 2] * m / s + ax.clear() + ax.plot(x, y) + expected_xlabel = "$q_{x}\\;/\\;\\left(\\rm{m} / \\rm{s}\\right)$" + assert ax.xaxis.get_label().get_text() == expected_xlabel _matplotlib.pyplot.close() From 3341aa34e14504f845af8f9ff1b60cf4c1f2854b Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 21 Jan 2020 20:15:11 -0700 Subject: [PATCH 11/14] tweak docs and docstring formatting --- docs/_static/mpl_fig3.png | Bin 0 -> 22200 bytes docs/usage.rst | 42 +++++++++++++++---------------- unyt/mpl_interface.py | 34 ++++++++++++------------- unyt/tests/test_mpl_interface.py | 2 ++ 4 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 docs/_static/mpl_fig3.png diff --git a/docs/_static/mpl_fig3.png b/docs/_static/mpl_fig3.png new file mode 100644 index 0000000000000000000000000000000000000000..54ff844f7a41a2f821b4414f6fafaff2e224052a GIT binary patch literal 22200 zcmeFZcT`o)mo0h#Ns>e)M-KujNEXQ$P(Y%flCywh$skctqJW4>21NuBNs@C;l9Zft zkensMTl@HR_pkfjzPHDCW4yl}V|@DIK4(|$s@gTznscrSR8f*4IZbyOg+h_Y$x5rD zP}n{w6xKKa9{kJIU&GVz*C~gaa`y?~$AjQe0Q^q)L{`%Qg(5RV{=@nrm1++EDC~G! z!%@xF)X~Mz-UMZB==j9S*3rt`h{f5&-of0~Mu3}-o1cs2v7_S?Q68TExXx{BZ^pwG z{P8Xd#e$NPzH#3*ZfV3_=dIJ|$$HIPTqB=i(S4?rKw1YrWfdE6BOjsjqj$ zVn9ptX{w1(igk{hoZL>}vJV=5Z0_Ky zNJ~rCwS7SaA)lkAybf2%uYJP42v;Xf@1t(R<>6PSKOoWW7v7>An0U6Lyx8(!`k zLHa|}M&6gF#~%<76QA?0?CN1x;oH})i*LBU{M@!4% z)DyU!w1P1oaV@V{UA_3;bi_Bk@|bVmzR7DznYPmW`0-T}n@MOG-ZU~Qzsdct37EAcaIBIWi z?`rQUeEhCbm(_)KKNv3XD>9K6kib+FKdX|-QC?h*3sA3_we-0 z5~_d|cj(Vdn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ZB%xhd)D*jS3v0&l$gp* z&S_nq7d1|p+LJ|W7{4MET+Ytxo3yKk@B3;r8e(4(s9xPB`g(5G^pn$(jaQ^~k(q+MNI2UdRSdR()s^5k|UJln*mR;yL;R%gA@nVnc(do`|^ zPp(?|ZMR1PaSJLh?k=sixH>|-c|m0=-jR_&Ufuhr_n~qw1wTT-?Gu^2%E9T6>)sZp ze;@R1+e@}0J;iWjNvYH6+S7Wv!Sh6qmHpvlpLnOmFjrthbwsOkD5Ttq>X zzI0HWc-*+GPcdJ=E>)}5?gyvaR8wbYHw&|eJZ|6X7t9Jv1)+TM9m&}Mg0shFT-1NE zVt4L&pt0;d?;Yd|JW*%aRY9_48#`$XJO2n)oM0W ztg*eFlCxvS!&o+4qA?0C!8?q}uq&U*is5nH$7*(;1Nnclz`zh zi#9_WX4-vYHg6!!IGz2!oW~{nIUXB*;zJ@LD90G-4WQ$a@z3Na00*K8aB_bEe4hdi zkn?kwz`IdS&QCTy@Mt` context +manager, Matplotlib will label the x and y axes with the units. >>> import matplotlib.pyplot as plt >>> from unyt import s, K, matplotlib_support @@ -1211,11 +1213,24 @@ You can change the plotted units without affecting the original data. .. image:: _static/mpl_fig2.png -There are three ways to use the context manager. +It is also possible to set the label style, the choices ``"()"``, ``"[]"`` and +``"/"`` are supported. + + >>> import matplotlib.pyplot as plt + >>> from unyt import s, K, matplotlib_support + >>> matplotlib_support.label_style = "[]" + >>> with matplotlib_support: + ... plt.plot([0, 1, 2]*s, [3, 4, 5]*K) + ... plt.show() + [] + +.. image:: _static/mpl_fig3.png + +There are three ways to use the context manager: 1. As a conventional context manager in a ``with`` statement as shown above -2. As a feature toggle in an interactive session +2. As a feature toggle in an interactive session: >>> import matplotlib.pyplot as plt >>> from unyt import s, K, matplotlib_support @@ -1225,23 +1240,8 @@ There are three ways to use the context manager. >>> plt.show() >>> matplotlib_support.disable() -3. As an enable for a complete session +3. As an enable for a complete session: >>> import unyt >>> unyt.matplotlib_support() >>> import matplotlib.pyplot as plt - -It is possible to set the label style. - - >>> import matplotlib.pyplot as plt - >>> from unyt import s, K, matplotlib_support - >>> matplotlib_support.label_style = "[]" - >>> with matplotlib_support: - ... plt.plot([0, 1, 2]*s, [3, 4, 5]*K) - ... plt.show() - [] - -.. note:: - - - This feature works in Matplotlib versions 2.2.4 and above - - Matplotlib is not a dependency of Unyt diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index d579cdaf..e82d6db8 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -111,7 +111,8 @@ def convert(value, unit, axis): Raises ------ - ConversionError if unit does not have the same dimensions as value + UnitConversionError if unit does not have the same dimensions as value or + if we don't know how to convert value. """ converted_value = value if isinstance(unit, str) or isinstance(unit, Unit): @@ -127,19 +128,18 @@ def convert(value, unit, axis): return converted_value class matplotlib_support: - """Context manager for experimenting with Unyt in Matplotlib + """Context manager for setting up integration with Unyt in Matplotlib Parameters ---------- - label_style : string, one from the set {'()', '[]', '/'} - The axis label style. - '()' -> '(unit)' - '[]' -> '[unit]' - '/' -> 'q / unit' - SI standard where label is a mathematical expression. - 'q' is a generic quantity symbol and for a value on the axis, x, - the equation is q = x * unit. + label_style : str + One of the following set, ``{'()', '[]', '/'}``. These choices correspond to the following + unit labels: + + * ``'()'`` -> ``'(unit)'`` + * ``'[]'`` -> ``'[unit]'`` + * ``'/'`` -> ``'q_x / unit'`` """ def __init__(self, label_style="()"): @@ -151,14 +151,12 @@ def __call__(self): @property def label_style(self): - """label_style : string, one from the set {'()', '[]', '/'} - The axis label style. - '()' -> '(unit)' - '[]' -> '[unit]' - '/' -> 'q / unit' - SI standard where label is a mathematical expression. - 'q' is a generic quantity symbol and for a value on the axis, x, - the equation is q = x * unit. + """str: One of the following set, ``{'()', '[]', '/'}``. These choices correspond to the following + unit labels: + + * ``'()'`` -> ``'(unit)'`` + * ``'[]'`` -> ``'[unit]'`` + * ``'/'`` -> ``'q_x / unit'`` """ return self._labelstyle diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index ace8b403..72b93c47 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -36,6 +36,7 @@ def test_label(ax): assert ax.xaxis.get_label().get_text() == expected_xlabel expected_ylabel = "$\\left(\\rm{K}\\right)$" assert ax.yaxis.get_label().get_text() == expected_ylabel + _matplotlib.pyplot.close() @check_matplotlib @@ -193,3 +194,4 @@ def test_labelstyle(): expected_xlabel = "$q_{x}\\;/\\;\\left(\\rm{m} / \\rm{s}\\right)$" assert ax.xaxis.get_label().get_text() == expected_xlabel _matplotlib.pyplot.close() + matplotlib_support.disable() From 2a4f8748787f6fb71a1aca62623c37637b28ba72 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 21 Jan 2020 21:09:22 -0700 Subject: [PATCH 12/14] fix formatting --- unyt/mpl_interface.py | 14 +++++--------- unyt/tests/test_mpl_interface.py | 5 +---- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/unyt/mpl_interface.py b/unyt/mpl_interface.py index e82d6db8..16c2ce49 100644 --- a/unyt/mpl_interface.py +++ b/unyt/mpl_interface.py @@ -14,11 +14,7 @@ try: - from matplotlib.units import ( - ConversionInterface, - AxisInfo, - registry, - ) + from matplotlib.units import ConversionInterface, AxisInfo, registry except ImportError: pass else: @@ -134,8 +130,8 @@ class matplotlib_support: ---------- label_style : str - One of the following set, ``{'()', '[]', '/'}``. These choices correspond to the following - unit labels: + One of the following set, ``{'()', '[]', '/'}``. These choices + correspond to the following unit labels: * ``'()'`` -> ``'(unit)'`` * ``'[]'`` -> ``'[unit]'`` @@ -151,8 +147,8 @@ def __call__(self): @property def label_style(self): - """str: One of the following set, ``{'()', '[]', '/'}``. These choices correspond to the following - unit labels: + """str: One of the following set, ``{'()', '[]', '/'}``. + These choices correspond to the following unit labels: * ``'()'`` -> ``'(unit)'`` * ``'[]'`` -> ``'[unit]'`` diff --git a/unyt/tests/test_mpl_interface.py b/unyt/tests/test_mpl_interface.py index 72b93c47..198c8a45 100644 --- a/unyt/tests/test_mpl_interface.py +++ b/unyt/tests/test_mpl_interface.py @@ -119,10 +119,7 @@ def test_list_label(ax): def test_errorbar(ax): x = unyt_array([8, 9, 10], "cm") y = unyt_array([8, 9, 10], "kg") - y_scatter = [ - unyt_array([0.1, 0.2, 0.3], "kg"), - unyt_array([0.1, 0.2, 0.3], "kg"), - ] + y_scatter = [unyt_array([0.1, 0.2, 0.3], "kg"), unyt_array([0.1, 0.2, 0.3], "kg")] x_lims = (unyt_quantity(5, "cm"), unyt_quantity(12, "cm")) y_lims = (unyt_quantity(5, "kg"), unyt_quantity(12, "kg")) From a2eb1217714540edaa2ac9b6ed7b976094d734f6 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 21 Jan 2020 21:19:40 -0700 Subject: [PATCH 13/14] add matplotlib to doc requirements --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 677daf5c..df8aee05 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,4 +2,5 @@ numpy sympy astropy pint -sphinx==1.7.9 \ No newline at end of file +matplotlib +sphinx \ No newline at end of file From 131a2c8adab5ad6e5494ae3f67e68a9173c6e005 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 21 Jan 2020 21:22:05 -0700 Subject: [PATCH 14/14] slim down doc requirements --- docs/requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index df8aee05..5b14b3f3 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,4 @@ numpy sympy -astropy -pint matplotlib sphinx \ No newline at end of file