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

ENH: add colorbar.set_aspect by jklymak · Pull Request #22103 · matplotlib/matplotlib · GitHub

Repository navigation

Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) 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
30 changes: 30 additions & 0 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 @@ -1015,6 +1015,36 @@ def _set_scale(self, scale, **kwargs):
else:
self.__scale = scale

def set_aspect(self, aspect):
"""
Set ratio of the long axis to short axis. Note this only works for axes
created by `~.FigureBase.colorbar`, `~.colorbar.make_axes`, or
`~.colorbar.make_axes_grdispec`. User-created axes should be changed by
the user.

Parameters:
-----------
aspect : float
"""
if not hasattr(self.ax, '_colorbar_info'):
raise RuntimeError('Colorbar cannot change the aspect ratio of '
'user-defined axes.')
self.ax._colorbar_info['aspect'] = aspect
if self.orientation == 'horizontal':
aspect = 1 / aspect
self.ax.set_box_aspect(aspect)
self.ax.set_aspect('auto')

def get_aspect(self):
"""
Get the ratio of long to short axis for the colorbar.
"""
if hasattr(self.ax, '_colorbar_info'):
return self.ax._colorbar_info['aspect']
else:
return self.ax.get_box_aspect()


def remove(self):
"""
Remove this colorbar from the figure.
Expand Down

Back | FazBrowse Home | New Git URL