Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: add test
  • Loading branch information
jklymak committed May 28, 2021
commit 549e0e7f550bc8614ed9bec3bdbc8c60c55e09ac
3 changes: 1 addition & 2 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,7 @@ def set_alpha(self, alpha):

def remove(self):
"""Remove this colorbar from the figure."""
self.ax.inner_ax.remove()
self.ax.outer_ax.remove()
self.ax.remove()

def _ticker(self, locator, formatter):
"""
Expand Down
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,24 @@ def test_axes_handles_same_functions(fig_ref, fig_test):
caxx.set_position([0.92, 0.1, 0.02, 0.7])


@check_figures_equal(extensions=["png"])
def test_colorbar_reuse_axes(fig_ref, fig_test):
ax = fig_ref.add_subplot()
pc = ax.imshow(np.arange(100).reshape(10, 10))
cb = fig_ref.colorbar(pc)
cb2 = fig_ref.colorbar(pc, extend='both')

ax = fig_test.add_subplot()
pc = ax.imshow(np.arange(100).reshape(10, 10))
cb = fig_test.colorbar(pc, extend='both')
cb2 = fig_test.colorbar(pc)
# Clear and re-use the same colorbar axes
cb.ax.cla()
cb2.ax.cla()
cb = fig_test.colorbar(pc, cax=cb.ax)
cb2 = fig_test.colorbar(pc, cax=cb2.ax, extend='both')


def test_inset_colorbar_layout():
fig, ax = plt.subplots(constrained_layout=True, figsize=(3, 6))
pc = ax.imshow(np.arange(100).reshape(10, 10))
Expand Down