Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34bbed6

Browse files
committed
move _ticker function inside update_ticks
1 parent ad2687d commit 34bbed6

File tree

1 file changed

+71
-71
lines changed

1 file changed

+71
-71
lines changed

lib/matplotlib/colorbar.py

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def __init__(self, ax, cmap=None,
944944
if cbook.iterable(xticks):
945945
self.xlocator = ticker.FixedLocator(xticks, nbins=len(xticks))
946946
else:
947-
self.xlocator = xticks # Handle default in _ticker()
947+
self.xlocator = xticks
948948

949949
if cbook.iterable(yticks):
950950
self.ylocator = ticker.FixedLocator(yticks, nbins=len(yticks))
@@ -1015,9 +1015,77 @@ def update_ticks(self):
10151015
Force the update of the ticks and ticklabels. This must be
10161016
called whenever the tick locator and/or tick formatter changes.
10171017
"""
1018+
def _make_ticker(norm):
1019+
"""
1020+
Return the sequence of ticks (colorbar data locations),
1021+
ticklabels (strings), and the corresponding offset string.
1022+
"""
1023+
if norm is self.norm.norm1:
1024+
_values = self._xvalues
1025+
_boundaries = self._xboundaries
1026+
boundaries = self.xboundaries
1027+
locator = self.xlocator
1028+
formatter = self.xformatter
1029+
else:
1030+
_values = self._yvalues
1031+
_boundaries = self._yboundaries
1032+
boundaries = self.yboundaries
1033+
locator = self.ylocator
1034+
formatter = self.yformatter
1035+
1036+
if locator is None:
1037+
if boundaries is None:
1038+
if isinstance(norm, colors.NoNorm):
1039+
nv = len(_values)
1040+
base = 1 + int(nv / 10)
1041+
locator = ticker.IndexLocator(base=base, offset=0)
1042+
elif isinstance(norm, colors.BoundaryNorm):
1043+
b = norm.boundaries
1044+
locator = ticker.FixedLocator(b, nbins=10)
1045+
elif isinstance(norm, colors.LogNorm):
1046+
locator = ticker.LogLocator(subs='all')
1047+
elif isinstance(norm, colors.SymLogNorm):
1048+
# The subs setting here should be replaced
1049+
# by logic in the locator.
1050+
locator = ticker.SymmetricalLogLocator(
1051+
subs=np.arange(1, 10),
1052+
linthresh=norm.linthresh,
1053+
base=10)
1054+
else:
1055+
# locator = ticker.AutoLocator()
1056+
locator = ticker.MaxNLocator(nbins=5)
1057+
else:
1058+
b = _boundaries[self._inside]
1059+
locator = ticker.FixedLocator(b, nbins=10)
1060+
if isinstance(norm, colors.NoNorm) and boundaries is None:
1061+
intv = _values[0], _values[-1]
1062+
else:
1063+
b = _boundaries[self._inside]
1064+
intv = b[0], b[-1]
1065+
locator.create_dummy_axis(minpos=intv[0])
1066+
formatter.create_dummy_axis(minpos=intv[0])
1067+
locator.set_view_interval(*intv)
1068+
locator.set_data_interval(*intv)
1069+
formatter.set_view_interval(*intv)
1070+
formatter.set_data_interval(*intv)
1071+
1072+
b = np.array(locator())
1073+
if isinstance(locator, ticker.LogLocator):
1074+
eps = 1e-10
1075+
b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))]
1076+
else:
1077+
eps = (intv[1] - intv[0]) * 1e-10
1078+
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
1079+
# self._tick_data_values = b
1080+
ticks = self._locate(b, norm)
1081+
formatter.set_locs(b)
1082+
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
1083+
offset_string = formatter.get_offset()
1084+
return ticks, ticklabels, offset_string
1085+
10181086
ax = self.ax
1019-
xticks, xticklabels, xoffset_string = self._ticker(self.norm.norm1)
1020-
yticks, yticklabels, yoffset_string = self._ticker(self.norm.norm2)
1087+
xticks, xticklabels, xoffset_string = _make_ticker(self.norm.norm1)
1088+
yticks, yticklabels, yoffset_string = _make_ticker(self.norm.norm2)
10211089

10221090
ax.xaxis.set_ticks(xticks)
10231091
ax.set_xticklabels(xticklabels)
@@ -1121,74 +1189,6 @@ def _add_solids(self, X, Y, C):
11211189
or len(self._x) >= self.n_rasterize):
11221190
self.solids.set_rasterized(True)
11231191

1124-
def _ticker(self, norm):
1125-
"""
1126-
Return the sequence of ticks (colorbar data locations),
1127-
ticklabels (strings), and the corresponding offset string.
1128-
"""
1129-
if norm is self.norm.norm1:
1130-
_values = self._xvalues
1131-
_boundaries = self._xboundaries
1132-
boundaries = self.xboundaries
1133-
locator = self.xlocator
1134-
formatter = self.xformatter
1135-
else:
1136-
_values = self._yvalues
1137-
_boundaries = self._yboundaries
1138-
boundaries = self.yboundaries
1139-
locator = self.ylocator
1140-
formatter = self.yformatter
1141-
1142-
if locator is None:
1143-
if boundaries is None:
1144-
if isinstance(norm, colors.NoNorm):
1145-
nv = len(_values)
1146-
base = 1 + int(nv / 10)
1147-
locator = ticker.IndexLocator(base=base, offset=0)
1148-
elif isinstance(norm, colors.BoundaryNorm):
1149-
b = norm.boundaries
1150-
locator = ticker.FixedLocator(b, nbins=10)
1151-
elif isinstance(norm, colors.LogNorm):
1152-
locator = ticker.LogLocator(subs='all')
1153-
elif isinstance(norm, colors.SymLogNorm):
1154-
# The subs setting here should be replaced
1155-
# by logic in the locator.
1156-
locator = ticker.SymmetricalLogLocator(
1157-
subs=np.arange(1, 10),
1158-
linthresh=norm.linthresh,
1159-
base=10)
1160-
else:
1161-
# locator = ticker.AutoLocator()
1162-
locator = ticker.MaxNLocator(nbins=5)
1163-
else:
1164-
b = _boundaries[self._inside]
1165-
locator = ticker.FixedLocator(b, nbins=10)
1166-
if isinstance(norm, colors.NoNorm) and boundaries is None:
1167-
intv = _values[0], _values[-1]
1168-
else:
1169-
b = _boundaries[self._inside]
1170-
intv = b[0], b[-1]
1171-
locator.create_dummy_axis(minpos=intv[0])
1172-
formatter.create_dummy_axis(minpos=intv[0])
1173-
locator.set_view_interval(*intv)
1174-
locator.set_data_interval(*intv)
1175-
formatter.set_view_interval(*intv)
1176-
formatter.set_data_interval(*intv)
1177-
1178-
b = np.array(locator())
1179-
if isinstance(locator, ticker.LogLocator):
1180-
eps = 1e-10
1181-
b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))]
1182-
else:
1183-
eps = (intv[1] - intv[0]) * 1e-10
1184-
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
1185-
# self._tick_data_values = b
1186-
ticks = self._locate(b, norm)
1187-
formatter.set_locs(b)
1188-
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
1189-
offset_string = formatter.get_offset()
1190-
return ticks, ticklabels, offset_string
1191-
11921192
def _process_values(self, b=None, norm=None):
11931193
if norm is self.norm.norm1:
11941194
boundaries = self.xboundaries

0 commit comments

Comments
 (0)