Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ultraplot/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2934,8 +2934,14 @@ def _translate_cmap(cmap, lut=None, cyclic=None, listedthresh=None):
# WARNING: Apply default 'cyclic' property to native matplotlib colormaps
# based on known names. Maybe slightly dangerous but cleanest approach
lut = _not_none(lut, rc["image.lut"])
cyclic = _not_none(cyclic, cmap.name and cmap.name.lower() in CMAPS_CYCLIC)
name = getattr(cmap, "name", None)
cyclic = _not_none(cyclic, name and name.lower() in CMAPS_CYCLIC)
listedthresh = _not_none(listedthresh, rc["cmap.listedthresh"])
if not isinstance(cmap, mcolors.Colormap):
raise ValueError(
f"Invalid colormap type {type(cmap).__name__!r}. "
"Must be instance of matplotlib.colors.Colormap."
)

# Translate the colormap
# WARNING: Here we ignore 'N' in order to respect ultraplotrc lut sizes
Expand All @@ -2957,12 +2963,6 @@ def _translate_cmap(cmap, lut=None, cyclic=None, listedthresh=None):
cmap = DiscreteColormap(colors, name)
elif isinstance(cmap, mcolors.Colormap): # base class
pass
else:
raise ValueError(
f"Invalid colormap type {type(cmap).__name__!r}. "
"Must be instance of matplotlib.colors.Colormap."
)

# Apply hidden settings
cmap._rgba_bad = bad
cmap._rgba_under = under
Expand Down
8 changes: 5 additions & 3 deletions ultraplot/internals/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def _validate_color(value, alternative=None):
def _validate_bool_or_iterable(value):
if isinstance(value, bool):
return _validate_bool(value)
elif np.isiterable(value):
elif np.iterable(value):
return value
raise ValueError(f"{value!r} is not a valid bool or iterable of node labels.")

Expand Down Expand Up @@ -460,15 +460,15 @@ def _validate_float_or_iterable(value):
try:
return _validate_float(value)
except Exception:
if np.isiterable(value) and not isinstance(value, (str, bytes)):
if np.iterable(value) and not isinstance(value, (str, bytes)):
return tuple(_validate_float(item) for item in value)
raise ValueError(f"{value!r} is not a valid float or iterable of floats.")


def _validate_string_or_iterable(value):
if isinstance(value, str):
return _validate_string(value)
if np.isiterable(value) and not isinstance(value, (str, bytes)):
if np.iterable(value) and not isinstance(value, (str, bytes)):
values = tuple(value)
if all(isinstance(item, str) for item in values):
return values
Expand Down Expand Up @@ -601,6 +601,8 @@ def _yaml_table(rcdict, comment=True, description=False):

# Generate string
string = ""
if not data:
return string
keylen = len(max(rcdict, key=len))
vallen = len(max((tup[1] for tup in data), key=len))
for key, value, descrip in data:
Expand Down
8 changes: 4 additions & 4 deletions ultraplot/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
f"The {self.name!r} projection does not handle elliptical globes."
)

proj4_params = {"proj": "aitoff", "lon_0": central_longitude}
proj4_params = [("proj", "aitoff"), ("lon_0", central_longitude)]
super().__init__(
proj4_params,
central_longitude,
Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(
f"The {self.name!r} projection does not handle elliptical globes."
)

proj4_params = {"proj": "hammer", "lon_0": central_longitude}
proj4_params = [("proj", "hammer"), ("lon_0", central_longitude)]
super().__init__(
proj4_params,
central_longitude,
Expand Down Expand Up @@ -172,7 +172,7 @@ def __init__(
f"The {self.name!r} projection does not handle elliptical globes."
)

proj4_params = {"proj": "kav7", "lon_0": central_longitude}
proj4_params = [("proj", "kav7"), ("lon_0", central_longitude)]
super().__init__(
proj4_params,
central_longitude,
Expand Down Expand Up @@ -218,7 +218,7 @@ def __init__(
f"The {self.name!r} projection does not handle " "elliptical globes."
)

proj4_params = {"proj": "wintri", "lon_0": central_longitude}
proj4_params = [("proj", "wintri"), ("lon_0", central_longitude)]
super().__init__(
proj4_params,
central_longitude,
Expand Down
5 changes: 3 additions & 2 deletions ultraplot/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def inverted(self):

def transform_non_affine(self, a):
with np.errstate(divide="ignore", invalid="ignore"):
return np.rad2deg(np.arctan2(1, np.sinh(a)))
return np.rad2deg(np.arctan(np.sinh(a)))


class SineLatitudeScale(_Scale, mscale.ScaleBase):
Expand Down Expand Up @@ -853,7 +853,8 @@ def __init__(self, threshs, scales, zero_dists=None):
with np.errstate(divide="ignore", invalid="ignore"):
dists = np.concatenate((threshs[:1], dists / scales[:-1]))
if zero_dists is not None:
dists[scales[:-1] == 0] = zero_dists
zero_idx = np.flatnonzero(scales[:-1] == 0) + 1
dists[zero_idx] = zero_dists
self._dists = dists

def inverted(self):
Expand Down
Loading
Loading