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

Skip to content

Commit 87374d4

Browse files
committed
Bugfix: save colorbar axis label so it won't get lost
svn path=/trunk/matplotlib/; revision=3991
1 parent 8e25df6 commit 87374d4

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

lib/matplotlib/colorbar.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def __init__(self, ax, cmap=None,
155155
self.filled = filled
156156
self.solids = None
157157
self.lines = None
158+
self.set_label('')
158159
if cbook.iterable(ticks):
159160
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
160161
else:
@@ -183,6 +184,7 @@ def draw_all(self):
183184
self._config_axes(X, Y)
184185
if self.filled:
185186
self._add_solids(X, Y, C)
187+
self._set_label()
186188

187189
def _config_axes(self, X, Y):
188190
'''
@@ -220,11 +222,17 @@ def _config_axes(self, X, Y):
220222
ax.set_xticklabels(ticklabels)
221223
ax.xaxis.get_major_formatter().set_offset_string(offset_string)
222224

223-
def set_label(self, label, **kw):
225+
def _set_label(self):
224226
if self.orientation == 'vertical':
225-
self.ax.set_ylabel(label, **kw)
227+
self.ax.set_ylabel(self._label, **self._labelkw)
226228
else:
227-
self.ax.set_xlabel(label, **kw)
229+
self.ax.set_xlabel(self._label, **self._labelkw)
230+
231+
def set_label(self, label, **kw):
232+
self._label = label
233+
self._labelkw = kw
234+
self._set_label()
235+
228236

229237
def _outline(self, X, Y):
230238
'''
@@ -556,6 +564,10 @@ def notify(self, mappable):
556564
is changed.
557565
'''
558566
cm.ScalarMappable.notify(self, mappable)
567+
# We are using an ugly brute-force method: clearing and
568+
# redrawing the whole thing. The problem is that if any
569+
# properties have been changed by methods other than the
570+
# colorbar methods, those changes will be lost.
559571
self.ax.cla()
560572
self.draw_all()
561573
#if self.vmin != self.norm.vmin or self.vmax != self.norm.vmax:

0 commit comments

Comments
 (0)