Skip to content

Commit

Permalink
DEP: drop support for matplotlib<3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Jun 25, 2023
1 parent 5d3a1f4 commit 407b303
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
55 changes: 7 additions & 48 deletions cmyt/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
import re
import sys
from typing import TYPE_CHECKING, Dict, Final, Iterable, Literal, Optional, Tuple

import matplotlib
import matplotlib as mpl
import numpy as np
from matplotlib.colors import Colormap, LinearSegmentedColormap, ListedColormap
from more_itertools import always_iterable

# type aliases

Expand Down Expand Up @@ -37,25 +35,6 @@
)


def version_tuple(version: str) -> Tuple[int, ...]:
elems = version.split(".")
if len(elems) > 3:
elems = elems[:3]

if not elems[-1].isnumeric():
# allow alpha/beta/release candidate versions
match = re.search(r"^\d+", elems[-1])
if match is None:
elems.pop()
else:
elems[-1] = match.group()

return tuple(int(_) for _ in elems)


MPL_VERSION = version_tuple(matplotlib.__version__)


def prefix_name(name: str) -> str:
if not name.startswith(_CMYT_PREFIX):
return f"{_CMYT_PREFIX}{name}"
Expand All @@ -79,20 +58,6 @@ def unprefix_name(name: str) -> str:
return name


def _register_mpl_cmap(cmap: Colormap) -> None:
"""
An adapter for matplotlib that works transparently with
either API (historical and post 3.5.0) while dodging deprecation
warnings.
"""
if MPL_VERSION >= (3, 5, 0):
matplotlib.colormaps.register(cmap)
else:
from matplotlib.cm import register_cmap

register_cmap(cmap=cmap)


def register_colormap(
name: str,
*,
Expand All @@ -110,22 +75,15 @@ def register_colormap(
mpl_cmap = ListedColormap(colors, name=name, N=256)
else:
raise TypeError("color_dict or colors must be provided")
mpl_cmap_r = mpl_cmap.reversed()
_register_mpl_cmap(mpl_cmap)
_register_mpl_cmap(mpl_cmap_r)

mpl.colormaps.register(mpl_cmap)
mpl.colormaps.register(mpl_cmap.reversed())

# return cmaps with unprefixed names for registration as importable objects
if MPL_VERSION >= (3, 4):
cmap = mpl_cmap.copy()
else:
if color_dict is not None:
cmap = LinearSegmentedColormap(name=name, segmentdata=color_dict, N=256)
elif colors is not None:
cmap = ListedColormap(colors, name=name, N=256)
cmap = mpl_cmap.copy()
cmap.name = unprefix_name(name)
cmap_r = cmap.reversed()

return cmap, cmap_r
return cmap, cmap.reversed()


graySCALE_CONVERSION_SPACE = "JCh"
Expand Down Expand Up @@ -197,6 +155,7 @@ def create_cmap_overview(
Defaults to False.
"""
import matplotlib.pyplot as plt
from more_itertools import always_iterable

if subset is None:
subset = cmyt_cmaps
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ keywords = [
requires-python = ">=3.8"
dependencies = [
"colorspacious>=1.1.2",
"matplotlib>=3.2.0",
"matplotlib>=3.5.0",
"more-itertools>=8.4",
"numpy>=1.17.4",
]
Expand Down

0 comments on commit 407b303

Please # to comment.