|
11 | 11 | End-users most likely won't need to directly use this module's API. |
12 | 12 | """ |
13 | 13 |
|
14 | | -import copy |
15 | 14 | import logging |
16 | 15 | import textwrap |
17 | 16 |
|
18 | 17 | import numpy as np |
19 | 18 |
|
20 | 19 | import matplotlib as mpl |
21 | | -from matplotlib import _api, collections, cm, colors, contour, ticker |
| 20 | +from matplotlib import _api, cbook, collections, cm, colors, contour, ticker |
22 | 21 | import matplotlib.artist as martist |
23 | 22 | import matplotlib.patches as mpatches |
24 | 23 | import matplotlib.path as mpath |
@@ -1152,20 +1151,24 @@ def _mesh(self): |
1152 | 1151 | These are scaled between vmin and vmax, and already handle colorbar |
1153 | 1152 | orientation. |
1154 | 1153 | """ |
1155 | | - # copy the norm and change the vmin and vmax to the vmin and |
1156 | | - # vmax of the colorbar, not the norm. This allows the situation |
1157 | | - # where the colormap has a narrower range than the colorbar, to |
1158 | | - # accommodate extra contours: |
1159 | | - norm = copy.deepcopy(self.norm) |
1160 | | - norm.vmin = self.vmin |
1161 | | - norm.vmax = self.vmax |
1162 | 1154 | y, extendlen = self._proportional_y() |
1163 | | - # invert: |
1164 | | - if (isinstance(norm, (colors.BoundaryNorm, colors.NoNorm)) or |
1165 | | - self.boundaries is not None): |
1166 | | - y = y * (self.vmax - self.vmin) + self.vmin # not using a norm. |
| 1155 | + # Use the vmin and vmax of the colorbar, which may not be the same |
| 1156 | + # as the norm. There are situations where the colormap has a |
| 1157 | + # narrower range than the colorbar and we want to accommodate the |
| 1158 | + # extra contours. |
| 1159 | + if (isinstance(self.norm, (colors.BoundaryNorm, colors.NoNorm)) |
| 1160 | + or self.boundaries is not None): |
| 1161 | + # not using a norm. |
| 1162 | + y = y * (self.vmax - self.vmin) + self.vmin |
1167 | 1163 | else: |
1168 | | - y = norm.inverse(y) |
| 1164 | + # Update the norm values in a context manager as it is only |
| 1165 | + # a temporary change and we don't want to propagate any signals |
| 1166 | + # attached to the norm (callbacks.blocked). |
| 1167 | + with self.norm.callbacks.blocked(), \ |
| 1168 | + cbook._setattr_cm(self.norm, |
| 1169 | + vmin=self.vmin, |
| 1170 | + vmax=self.vmax): |
| 1171 | + y = self.norm.inverse(y) |
1169 | 1172 | self._y = y |
1170 | 1173 | X, Y = np.meshgrid([0., 1.], y) |
1171 | 1174 | if self.orientation == 'vertical': |
|
0 commit comments