FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adding cla and remove to ColorbarAxes by greglucas · Pull Request #20323 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 11 additions & 2 deletions lib/matplotlib/colorbar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ def _set_inner_bounds(self, bounds):
self.inner_ax._axes_locator = _TransformedBoundsLocator(
bounds, self.outer_ax.transAxes)

def cla(self):
"""Clear the axes."""
self.inner_ax.cla()
self.outer_ax.cla()

def remove(self):
"""Remove the axes."""
self.inner_ax.remove()
self.outer_ax.remove()


class _ColorbarSpine(mspines.Spine):
def __init__(self, axes):
Expand Down Expand Up @@ -874,8 +884,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
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,17 @@ def test_inset_colorbar_layout():
np.testing.assert_allclose(cb.ax.get_position().bounds,
[0.87, 0.342, 0.0237, 0.315], atol=0.01)
assert cb.ax.outer_ax in ax.child_axes


@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)

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

Back | FazBrowse Home | New Git URL