We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7fc7cd6 commit 827f571Copy full SHA for 827f571
lib/matplotlib/colorbar.py
@@ -900,8 +900,7 @@ def set_alpha(self, alpha):
900
901
def remove(self):
902
"""Remove this colorbar from the figure."""
903
- self.ax.inner_ax.remove()
904
- self.ax.outer_ax.remove()
+ self.ax.remove()
905
906
def _ticker(self, locator, formatter):
907
"""
lib/matplotlib/tests/test_colorbar.py
@@ -759,6 +759,24 @@ def test_axes_handles_same_functions(fig_ref, fig_test):
759
caxx.set_position([0.92, 0.1, 0.02, 0.7])
760
761
762
+@check_figures_equal(extensions=["png"])
763
+def test_colorbar_reuse_axes(fig_ref, fig_test):
764
+ ax = fig_ref.add_subplot()
765
+ pc = ax.imshow(np.arange(100).reshape(10, 10))
766
+ cb = fig_ref.colorbar(pc)
767
+ cb2 = fig_ref.colorbar(pc, extend='both')
768
+
769
+ ax = fig_test.add_subplot()
770
771
+ cb = fig_test.colorbar(pc, extend='both')
772
+ cb2 = fig_test.colorbar(pc)
773
+ # Clear and re-use the same colorbar axes
774
+ cb.ax.cla()
775
+ cb2.ax.cla()
776
+ cb = fig_test.colorbar(pc, cax=cb.ax)
777
+ cb2 = fig_test.colorbar(pc, cax=cb2.ax, extend='both')
778
779
780
def test_inset_colorbar_layout():
781
fig, ax = plt.subplots(constrained_layout=True, figsize=(3, 6))
782
pc = ax.imshow(np.arange(100).reshape(10, 10))
0 commit comments