Skip to content

Commit 5e9ac1b

Browse files
authored
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 <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [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>
1 parent 1bcf97f commit 5e9ac1b

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

docs/source/conf.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def generate_apidocs(*args):
139139
"github_user": "Project-MONAI",
140140
"github_repo": "MONAI",
141141
"github_version": "dev",
142-
"doc_path": "docs/",
142+
"doc_path": "docs/source",
143143
"conf_py_path": "/docs/",
144144
"VERSION": version,
145145
}
@@ -167,17 +167,10 @@ def setup(app):
167167

168168

169169
# -- Linkcode configuration --------------------------------------------------
170-
DEFAULT_REF = "dev"
171-
if os.environ.get("GITHUB_REF_TYPE", "branch") == "tag":
172-
# When building a tag, link to the tag itself
173-
git_ref = os.environ.get("GITHUB_REF", DEFAULT_REF)
174-
else:
175-
git_ref = os.environ.get("GITHUB_SHA", DEFAULT_REF)
176-
177170
DEFAULT_REPOSITORY = "Project-MONAI/MONAI"
178171
repository = os.environ.get("GITHUB_REPOSITORY", DEFAULT_REPOSITORY)
179172

180-
base_code_url = f"https://github.com/{repository}/blob/{git_ref}"
173+
base_code_url = f"https://github.com/{repository}/blob/{version}"
181174
MODULE_ROOT_FOLDER = "monai"
182175

183176

@@ -208,7 +201,7 @@ def linkcode_resolve(domain, info):
208201
except TypeError:
209202
# e.g. object is a typing.Union
210203
return None
211-
file = os.path.relpath(file, os.path.abspath(".."))
204+
file = os.path.relpath(file, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
212205
if not file.startswith(MODULE_ROOT_FOLDER):
213206
# e.g. object is a typing.NewType
214207
return None

monai/visualize/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
from monai.utils.type_conversion import convert_data_type, convert_to_dst_type
2525

2626
if TYPE_CHECKING:
27-
from matplotlib import cm
2827
from matplotlib import pyplot as plt
2928
else:
3029
plt, _ = optional_import("matplotlib", name="pyplot")
31-
cm, _ = optional_import("matplotlib", name="cm")
3230

3331
__all__ = ["matshow3d", "blend_images"]
3432

@@ -210,7 +208,7 @@ def blend_images(
210208
image = repeat(image, 3, axis=0)
211209

212210
def get_label_rgb(cmap: str, label: NdarrayOrTensor) -> NdarrayOrTensor:
213-
_cmap = cm.get_cmap(cmap)
211+
_cmap = plt.colormaps.get_cmap(cmap)
214212
label_np, *_ = convert_data_type(label, np.ndarray)
215213
label_rgb_np = _cmap(label_np[0])
216214
label_rgb_np = np.moveaxis(label_rgb_np, -1, 0)[:3]

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ einops
3636
transformers>=4.36.0
3737
mlflow>=2.12.2
3838
clearml>=1.10.0rc0
39-
matplotlib!=3.5.0
39+
matplotlib>=3.6.3
4040
tensorboardX
4141
types-PyYAML
4242
pyyaml

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ all =
6868
transformers<4.22; python_version <= '3.10'
6969
mlflow>=2.12.2
7070
clearml>=1.10.0rc0
71-
matplotlib
71+
matplotlib>=3.6.3
7272
tensorboardX
7373
pyyaml
7474
fire
@@ -127,7 +127,7 @@ transformers =
127127
mlflow =
128128
mlflow>=2.12.2
129129
matplotlib =
130-
matplotlib
130+
matplotlib>=3.6.3
131131
clearml =
132132
clearml
133133
tensorboardX =

tests/test_matshow3d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def test_3d_rgb(self):
114114
every_n=2,
115115
frame_dim=-1,
116116
channel_dim=0,
117+
fill_value=0,
117118
show=False,
118119
)
119120

0 commit comments

Comments
 (0)