From 5e9ac1bf4e3bfa73dcdb1c604554c5f7f41075b3 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 17 May 2024 16:08:14 +0800 Subject: [PATCH] Fix matplotlib 3.9.0 has no attribute 'get_cmap` (#7780) Fixes #7776 ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- docs/source/conf.py | 13 +++---------- monai/visualize/utils.py | 4 +--- requirements-dev.txt | 2 +- setup.cfg | 4 ++-- tests/test_matshow3d.py | 1 + 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 782b585c9f..543372ebc7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -139,7 +139,7 @@ def generate_apidocs(*args): "github_user": "Project-MONAI", "github_repo": "MONAI", "github_version": "dev", - "doc_path": "docs/", + "doc_path": "docs/source", "conf_py_path": "/docs/", "VERSION": version, } @@ -167,17 +167,10 @@ def setup(app): # -- Linkcode configuration -------------------------------------------------- -DEFAULT_REF = "dev" -if os.environ.get("GITHUB_REF_TYPE", "branch") == "tag": - # When building a tag, link to the tag itself - git_ref = os.environ.get("GITHUB_REF", DEFAULT_REF) -else: - git_ref = os.environ.get("GITHUB_SHA", DEFAULT_REF) - DEFAULT_REPOSITORY = "Project-MONAI/MONAI" repository = os.environ.get("GITHUB_REPOSITORY", DEFAULT_REPOSITORY) -base_code_url = f"https://github.com/{repository}/blob/{git_ref}" +base_code_url = f"https://github.com/{repository}/blob/{version}" MODULE_ROOT_FOLDER = "monai" @@ -208,7 +201,7 @@ def linkcode_resolve(domain, info): except TypeError: # e.g. object is a typing.Union return None - file = os.path.relpath(file, os.path.abspath("..")) + file = os.path.relpath(file, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) if not file.startswith(MODULE_ROOT_FOLDER): # e.g. object is a typing.NewType return None diff --git a/monai/visualize/utils.py b/monai/visualize/utils.py index f6718fe7a5..88c9a0d66a 100644 --- a/monai/visualize/utils.py +++ b/monai/visualize/utils.py @@ -24,11 +24,9 @@ from monai.utils.type_conversion import convert_data_type, convert_to_dst_type if TYPE_CHECKING: - from matplotlib import cm from matplotlib import pyplot as plt else: plt, _ = optional_import("matplotlib", name="pyplot") - cm, _ = optional_import("matplotlib", name="cm") __all__ = ["matshow3d", "blend_images"] @@ -210,7 +208,7 @@ def blend_images( image = repeat(image, 3, axis=0) def get_label_rgb(cmap: str, label: NdarrayOrTensor) -> NdarrayOrTensor: - _cmap = cm.get_cmap(cmap) + _cmap = plt.colormaps.get_cmap(cmap) label_np, *_ = convert_data_type(label, np.ndarray) label_rgb_np = _cmap(label_np[0]) label_rgb_np = np.moveaxis(label_rgb_np, -1, 0)[:3] diff --git a/requirements-dev.txt b/requirements-dev.txt index 83bdae2a5c..09aeb22cac 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -36,7 +36,7 @@ einops transformers>=4.36.0 mlflow>=2.12.2 clearml>=1.10.0rc0 -matplotlib!=3.5.0 +matplotlib>=3.6.3 tensorboardX types-PyYAML pyyaml diff --git a/setup.cfg b/setup.cfg index 711d5c5558..086722914e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -68,7 +68,7 @@ all = transformers<4.22; python_version <= '3.10' mlflow>=2.12.2 clearml>=1.10.0rc0 - matplotlib + matplotlib>=3.6.3 tensorboardX pyyaml fire @@ -127,7 +127,7 @@ transformers = mlflow = mlflow>=2.12.2 matplotlib = - matplotlib + matplotlib>=3.6.3 clearml = clearml tensorboardX = diff --git a/tests/test_matshow3d.py b/tests/test_matshow3d.py index e54bb523e4..2eba310f4e 100644 --- a/tests/test_matshow3d.py +++ b/tests/test_matshow3d.py @@ -114,6 +114,7 @@ def test_3d_rgb(self): every_n=2, frame_dim=-1, channel_dim=0, + fill_value=0, show=False, )