From 26bfd50d9927e1de252400afac26effba9911f82 Mon Sep 17 00:00:00 2001 From: James Clark <70290797+jamesclark-Zapata@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:15:15 +0100 Subject: [PATCH] chore: Update minimum Python version (#61) * chore: Update minimum Python version * tmp: install orquestra-python-dev from branch * chore: fix typing issues * Revert "tmp: install orquestra-python-dev from branch" This reverts commit 7888b0b1f0f6292676006dbb02a2fc82ba3cb065. * fix: mypy mistakes axes3D for axes * fix: isort issues --------- Co-authored-by: Athena Caesura --- .github/workflows/coverage.yml | 2 +- .github/workflows/style.yml | 2 +- setup.cfg | 6 ++++-- src/orqviz/plot_utils.py | 14 ++++++++------ src/orqviz/scans/plots.py | 17 ++++++++--------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bc57c70..d5eb908 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest"] - python: ["3.8", "3.9", "3.10"] + python: ["3.9", "3.10", "3.11"] name: Coverage - Python ${{ matrix.python }} - ${{ matrix.os }} diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e7cf0b2..ef1db65 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -22,7 +22,7 @@ jobs: # Run jobs for a couple of Python versions. strategy: matrix: - python: ["3.8", "3.9", "3.10"] + python: ["3.9", "3.10", "3.11"] name: Style - Python ${{ matrix.python }} diff --git a/setup.cfg b/setup.cfg index 46b4ed6..2dbd068 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,9 @@ author_email = info@zapatacomputing.com, license = Apache Software License license_file = LICENSE classifiers = - Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 Operating System :: OS Independent License :: OSI Approved :: Apache Software License Topic :: Scientific/Engineering @@ -18,7 +20,7 @@ classifiers = package_dir = = src packages = find: -python_requires = >=3.7 +python_requires = >=3.9 install_requires = numpy>=1.14.6 diff --git a/src/orqviz/plot_utils.py b/src/orqviz/plot_utils.py index c9190d3..4c7e279 100644 --- a/src/orqviz/plot_utils.py +++ b/src/orqviz/plot_utils.py @@ -3,7 +3,9 @@ import matplotlib.pyplot as plt import matplotlib.ticker as tck +import mpl_toolkits import numpy as np +from matplotlib.cm import ScalarMappable def normalize_color_and_colorbar( @@ -40,9 +42,11 @@ def normalize_color_and_colorbar( "Provided ax does not contain an image in ax.images or ax.collections" ) from e - image.colorbar.remove() - image.set_clim(vmin=min_val, vmax=max_val) - image.set_cmap(cmap) + assert isinstance(image, ScalarMappable) + if image.colorbar is not None: + image.colorbar.remove() + image.set_clim(vmin=min_val, vmax=max_val) # type: ignore + image.set_cmap(cmap) # type: ignore fig.colorbar(image, ax=ax) @@ -62,7 +66,6 @@ def get_colorbar_from_ax( _, ax = _check_and_create_fig_ax(ax=ax) if image_index is None: - len_collections = len(ax.collections) len_images = len(ax.images) @@ -155,7 +158,6 @@ def _check_and_create_fig_ax( fig: Optional[plt.Figure] = None, ax: Optional[plt.Axes] = None, ) -> Tuple[plt.Figure, plt.Axes]: - if fig is None: fig = plt.gcf() @@ -167,7 +169,7 @@ def _check_and_create_fig_ax( def _check_and_create_3D_ax( ax: Optional[plt.Axes] = None, -) -> plt.Axes: +) -> mpl_toolkits.mplot3d.Axes3D: if ax is None: fig = plt.figure() ax = fig.add_subplot(projection="3d") diff --git a/src/orqviz/scans/plots.py b/src/orqviz/scans/plots.py index 444a679..46fd324 100644 --- a/src/orqviz/scans/plots.py +++ b/src/orqviz/scans/plots.py @@ -3,9 +3,6 @@ import matplotlib import numpy as np -# this import is unused but solves issues with older matplotlib versions and 3d plots -from mpl_toolkits.mplot3d import Axes3D - from ..plot_utils import _check_and_create_3D_ax, _check_and_create_fig_ax from .data_structures import Scan1DResult, Scan2DResult @@ -161,7 +158,9 @@ def plot_2D_scan_result_as_3D( plot_kwargs: kwargs for plotting with matplotlib.pyplot.plot_surface (plt.plot_surface) """ - ax = _check_and_create_3D_ax(ax=ax) + ax3D = _check_and_create_3D_ax(ax=ax) + + assert ax3D is not None x, y = scan2D_result._get_coordinates_on_directions( in_units_of_direction=in_units_of_direction @@ -171,10 +170,10 @@ def plot_2D_scan_result_as_3D( plot_kwargs_defaults = {"cmap": "viridis", "alpha": 0.8} plot_kwargs = {**plot_kwargs_defaults, **plot_kwargs} - ax.plot_surface(XX, YY, scan2D_result.values, **plot_kwargs) + ax3D.plot_surface(XX, YY, scan2D_result.values, **plot_kwargs) - ax.view_init(elev=35, azim=-70) + ax3D.view_init(elev=35, azim=-70) - ax.set_xlabel("Scan Direction x") - ax.set_ylabel("Scan Direction y") - ax.set_zlabel("Loss Value") + ax3D.set_xlabel("Scan Direction x") + ax3D.set_ylabel("Scan Direction y") + ax3D.set_zlabel("Loss Value")