Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5322bc6

Browse filesBrowse files
committed
move _ticker function inside update_ticks
1 parent ad2687d commit 5322bc6
Copy full SHA for 5322bc6

File tree

2 files changed

+73
-71
lines changed
Filter options

2 files changed

+73
-71
lines changed

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+71-71Lines 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

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
7171
from abc import ABCMeta
7272

73+
7374
class _ColorMapping(dict):
7475
def __init__(self, mapping):
7576
super(_ColorMapping, self).__init__(mapping)
@@ -889,6 +890,7 @@ class Norms:
889890
__metaclass__ = ABCMeta
890891
pass
891892

893+
892894
class Normalize(Norms):
893895
"""
894896
A class which, when called, can normalize data into

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.