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

Correctly pass location when constructing ImageGrid colorbar. by anntzer · Pull Request #25884 · matplotlib/matplotlib · GitHub

Repository navigation

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

Filter by extension

Filter by extension .png  (2) .py  (2) All 2 file types 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
15 changes: 3 additions & 12 deletions lib/mpl_toolkits/axes_grid1/axes_grid.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 @@ -22,23 +22,14 @@ def __init__(self, *args, orientation, **kwargs):
self.orientation = orientation
super().__init__(*args, **kwargs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Semi-OT, but got to this because you deleted cla(): This super().__init__ should not do anything, right? - Likely a leftover from the dedicated axes_grid colorbar classes?

anntzer May 14, 2023 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It does (should?), as CbarAxesBase is a mixin and will thus end up in the base classes of the actual colorbar axes class used by ImageGrid, and thus we need to forward arguments via super() (after extracting out orientation).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Indeed. Maybe that should be mentioned somewhere in the class? without that context, it's looks like object is the only parent. Either way, the PR is correct.


def colorbar(self, mappable, *, ticks=None, **kwargs):
orientation = (
"horizontal" if self.orientation in ["top", "bottom"] else
"vertical")
cb = self.figure.colorbar(mappable, cax=self, orientation=orientation,
ticks=ticks, **kwargs)
return cb
def colorbar(self, mappable, **kwargs):
return self.figure.colorbar(
mappable, cax=self, location=self.orientation, **kwargs)

def toggle_label(self, b):
axis = self.axis[self.orientation]
axis.toggle(ticklabels=b, label=b)

def cla(self):
orientation = self.orientation
super().cla()
self.orientation = orientation


_cbaraxes_class_factory = cbook._make_class_factory(CbarAxesBase, "Cbar{}")

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
16 changes: 6 additions & 10 deletions lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.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 @@ -701,11 +701,7 @@ def test_insetposition():
@image_comparison(['imagegrid_cbar_mode.png'],
remove_text=True, style='mpl20', tol=0.3)
def test_imagegrid_cbar_mode_edge():
# Remove this line when this test image is regenerated.
plt.rcParams['pcolormesh.snap'] = False

X, Y = np.meshgrid(np.linspace(0, 6, 30), np.linspace(0, 6, 30))
arr = np.sin(X) * np.cos(Y) + 1j*(np.sin(3*Y) * np.cos(Y/2.))
arr = np.arange(16).reshape((4, 4))

fig = plt.figure(figsize=(18, 9))

Expand All @@ -721,12 +717,12 @@ def test_imagegrid_cbar_mode_edge():
cbar_location=location,
cbar_size='20%',
cbar_mode='edge')
ax1, ax2, ax3, ax4, = grid
ax1, ax2, ax3, ax4 = grid

ax1.imshow(arr.real, cmap='nipy_spectral')
ax2.imshow(arr.imag, cmap='hot')
ax3.imshow(np.abs(arr), cmap='jet')
ax4.imshow(np.arctan2(arr.imag, arr.real), cmap='hsv')
ax1.imshow(arr, cmap='nipy_spectral')
ax2.imshow(arr.T, cmap='hot')
ax3.imshow(np.hypot(arr, arr.T), cmap='jet')
ax4.imshow(np.arctan2(arr, arr.T), cmap='hsv')

# In each row/column, the "first" colorbars must be overwritten by the
# "second" ones. To achieve this, clear out the axes first.
Expand Down

Back | FazBrowse Home | New Git URL