Skip to content

Commit c567af8

Browse files
committed
Cleanup cmap internals + support non-zero vcenter
This supports passing a loose `vcenter` keyword to `_parse_cmap` that gets added to `norm_kw` and sets `diverging=True`. It also supports non-zero `vcenter` in several places, improving default level selection and default discrete tick selection and supporting `symmetric` levels about non-zero center.
1 parent a2656d6 commit c567af8

File tree

3 files changed

+102
-75
lines changed

3 files changed

+102
-75
lines changed

proplot/axes/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,8 @@ def _add_colorbar(
10821082
# NOTE: In presence of BoundaryNorm or similar handle ticks with special
10831083
# DiscreteLocator or else get issues (see mpl #22233).
10841084
norm = mappable.norm
1085+
source = getattr(norm, '_norm', None)
1086+
vcenter = {'vcenter': getattr(source, 'vcenter', 0.0)}
10851087
formatter = _not_none(formatter, getattr(norm, '_labels', None), 'auto')
10861088
formatter = constructor.Formatter(formatter, **formatter_kw)
10871089
categorical = isinstance(formatter, mticker.FixedFormatter)
@@ -1093,14 +1095,14 @@ def _add_colorbar(
10931095
tickminor = False if categorical else rc['xy'[vert] + 'tick.minor.visible']
10941096
if isinstance(norm, mcolors.BoundaryNorm): # DiscreteNorm or BoundaryNorm
10951097
ticks = getattr(norm, '_ticks', norm.boundaries)
1096-
segmented = isinstance(getattr(norm, '_norm', None), pcolors.SegmentedNorm)
1098+
segmented = isinstance(source, pcolors.SegmentedNorm)
10971099
if locator is None:
10981100
if categorical or segmented:
10991101
locator = mticker.FixedLocator(ticks)
11001102
else:
1101-
locator = pticker.DiscreteLocator(ticks)
1103+
locator = pticker.DiscreteLocator(ticks, **vcenter)
11021104
if tickminor and minorlocator is None:
1103-
minorlocator = pticker.DiscreteLocator(ticks, minor=True)
1105+
minorlocator = pticker.DiscreteLocator(ticks, minor=True, **vcenter)
11041106

11051107
# Special handling for colorbar keyword arguments
11061108
# WARNING: Critical to not pass empty major locators in matplotlib < 3.5

0 commit comments

Comments
 (0)