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

Skip to content

Commit 8eaff42

Browse files
committed
FIX: Updating contour methods to work with norm callbacks
Quadcontourset overrides ScalarMappable's `changed()` function, which meant that autoscaling would get called with the wrong data too early. Therefore, we force an autoscale with the proper data earlier in the `Quadcontourset.changed()` function.
1 parent 7dc9896 commit 8eaff42

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/matplotlib/cm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,9 @@ def autoscale_None(self):
476476
"""
477477
if self._A is None:
478478
raise TypeError('You must first set_array for mappable')
479+
# If the norm updates the limits *self.changed()* will be called
480+
# through the callbacks attached to the norm
479481
self.norm.autoscale_None(self._A)
480-
self.changed()
481482

482483
def _add_checker(self, checker):
483484
"""

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ def _mesh(self):
10751075
# vmax of the colorbar, not the norm. This allows the situation
10761076
# where the colormap has a narrower range than the colorbar, to
10771077
# accommodate extra contours:
1078-
norm = copy.copy(self.norm)
1078+
norm = copy.deepcopy(self.norm)
10791079
norm.vmin = self.vmin
10801080
norm.vmax = self.vmax
10811081
x = np.array([0.0, 1.0])

lib/matplotlib/contour.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ def _make_paths(self, segs, kinds):
10271027
return [mpath.Path(seg) for seg in segs]
10281028

10291029
def changed(self):
1030+
# Force an autoscale immediately because self.to_rgba() calls
1031+
# autoscale_None() internally with the data passed to it,
1032+
# so if vmin/vmax are not set yet, this would override them with
1033+
# content from *cvalues* rather than levels like we want
1034+
self.norm.autoscale_None(self.levels)
10301035
tcolors = [(tuple(rgba),)
10311036
for rgba in self.to_rgba(self.cvalues, alpha=self.alpha)]
10321037
self.tcolors = tcolors

0 commit comments

Comments
 (0)