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

Skip to content

Commit 549e0e7

Browse files
committed
TST: add test
1 parent c750a34 commit 549e0e7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,7 @@ def set_alpha(self, alpha):
900900

901901
def remove(self):
902902
"""Remove this colorbar from the figure."""
903-
self.ax.inner_ax.remove()
904-
self.ax.outer_ax.remove()
903+
self.ax.remove()
905904

906905
def _ticker(self, locator, formatter):
907906
"""

lib/matplotlib/tests/test_colorbar.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,24 @@ def test_axes_handles_same_functions(fig_ref, fig_test):
759759
caxx.set_position([0.92, 0.1, 0.02, 0.7])
760760

761761

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+
pc = ax.imshow(np.arange(100).reshape(10, 10))
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+
762780
def test_inset_colorbar_layout():
763781
fig, ax = plt.subplots(constrained_layout=True, figsize=(3, 6))
764782
pc = ax.imshow(np.arange(100).reshape(10, 10))

0 commit comments

Comments
 (0)