Skip to content

Commit 294c9ee

Browse files
committed
Respect colorbar tickminor for discrete levels
This ensures tickminor=True is respected if user passes custom non-discrete locator (e.g. a MultipleLocator) with a BoundaryNorm normalizer (in which case a default minor DiscreteLocator is used) and ensures default rc['(x|y)tick.minor.visible'] setting of False is respected even if DiscreteLocator is passed.
1 parent e189a9b commit 294c9ee

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

Diff for: proplot/axes/base.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -1089,25 +1089,18 @@ def _add_colorbar(
10891089
locator = _not_none(locator, locator_default, None)
10901090
formatter = _not_none(formatter, formatter_default, 'auto')
10911091
formatter = constructor.Formatter(formatter, **formatter_kw)
1092-
categorical = isinstance(formatter, mticker.FixedFormatter)
1093-
discrete = isinstance(mappable.norm, pcolors.DiscreteNorm)
10941092
if locator is not None:
10951093
locator = constructor.Locator(locator, **locator_kw)
10961094
if minorlocator is not None:
10971095
minorlocator = constructor.Locator(minorlocator, **minorlocator_kw)
1098-
if isinstance(locator, pticker.DiscreteLocator):
1099-
if categorical: # no minor ticks and convert DiscreteLocator
1100-
locator = mticker.FixedLocator(np.array(locator.locs))
1101-
elif minorlocator is not None:
1102-
pass
1103-
elif tickminor or tickminor is None:
1104-
minorlocator = pticker.DiscreteLocator(np.array(locator.locs), minor=True) # noqa: E501
1105-
if tickminor is not None: # whether to apply minorticks_on()
1106-
pass
1107-
elif discrete or categorical: # never use the default minor locator
1108-
tickminor = False
1109-
else:
1110-
tickminor = rc[name + 'tick.minor.visible']
1096+
discrete = isinstance(locator, pticker.DiscreteLocator)
1097+
categorical = isinstance(formatter, mticker.FixedFormatter)
1098+
tickminor = False if categorical else rc[name + 'tick.minor.visible']
1099+
if categorical and discrete:
1100+
locator = mticker.FixedLocator(np.array(locator.locs)) # convert locator
1101+
if tickminor and isinstance(mappable.norm, mcolors.BoundaryNorm):
1102+
locs = np.array(locator.locs if discrete else mappable.norm.boundaries)
1103+
minorlocator = pticker.DiscreteLocator(locs, minor=True)
11111104

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

0 commit comments

Comments
 (0)