There was an error while loading. Please reload this page.
1 parent 08f4629 commit 51db38eCopy full SHA for 51db38e
2 files changed
lib/matplotlib/colorbar.py
@@ -285,6 +285,16 @@ def _set_inner_bounds(self, bounds):
285
self.inner_ax._axes_locator = _TransformedBoundsLocator(
286
bounds, self.outer_ax.transAxes)
287
288
+ def cla(self):
289
+ """Clear the axes."""
290
+ self.inner_ax.cla()
291
+ self.outer_ax.cla()
292
+
293
+ def remove(self):
294
+ """Remove the axes."""
295
+ self.inner_ax.remove()
296
+ self.outer_ax.remove()
297
298
299
class _ColorbarSpine(mspines.Spine):
300
def __init__(self, axes):
@@ -874,8 +884,7 @@ def set_alpha(self, alpha):
874
884
875
885
def remove(self):
876
886
"""Remove this colorbar from the figure."""
877
- self.ax.inner_ax.remove()
878
- self.ax.outer_ax.remove()
887
+ self.ax.remove()
879
888
880
889
def _ticker(self, locator, formatter):
881
890
"""
lib/matplotlib/tests/test_colorbar.py
@@ -771,3 +771,17 @@ def test_inset_colorbar_layout():
771
np.testing.assert_allclose(cb.ax.get_position().bounds,
772
[0.87, 0.342, 0.0237, 0.315], atol=0.01)
773
assert cb.ax.outer_ax in ax.child_axes
774
775
776
+@check_figures_equal(extensions=["png"])
777
+def test_colorbar_reuse_axes(fig_ref, fig_test):
778
+ ax = fig_ref.add_subplot()
779
+ pc = ax.imshow(np.arange(100).reshape(10, 10))
780
+ cb = fig_ref.colorbar(pc)
781
782
+ ax = fig_test.add_subplot()
783
784
+ cb = fig_test.colorbar(pc)
785
+ # Clear and re-use the same colorbar axes
786
+ cb.ax.cla()
787
+ cb = fig_test.colorbar(pc, cax=cb.ax)
0 commit comments