MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _ColorbarAxesLocator

Class _ColorbarAxesLocator

lib/matplotlib/colorbar.py:149–195  ·  view source on GitHub ↗

Shrink the Axes if there are triangular or rectangular extends.

Source from the content-addressed store, hash-verified

147
148
149class _ColorbarAxesLocator:
150 """
151 Shrink the Axes if there are triangular or rectangular extends.
152 """
153 def __init__(self, cbar):
154 self._cbar = cbar
155 self._orig_locator = cbar.ax._axes_locator
156
157 def __call__(self, ax, renderer):
158 if self._orig_locator is not None:
159 pos = self._orig_locator(ax, renderer)
160 else:
161 pos = ax.get_position(original=True)
162 if self._cbar.extend == 'neither':
163 return pos
164
165 y, extendlen = self._cbar._proportional_y()
166 if not self._cbar._extend_lower():
167 extendlen[0] = 0
168 if not self._cbar._extend_upper():
169 extendlen[1] = 0
170 len = sum(extendlen) + 1
171 shrink = 1 / len
172 offset = extendlen[0] / len
173 # we need to reset the aspect ratio of the axes to account
174 # of the extends...
175 if hasattr(ax, '_colorbar_info'):
176 aspect = ax._colorbar_info['aspect']
177 else:
178 aspect = False
179 # now shrink and/or offset to take into account the
180 # extend tri/rectangles.
181 if self._cbar.orientation == 'vertical':
182 if aspect:
183 self._cbar.ax.set_box_aspect(aspect*shrink)
184 pos = pos.shrunk(1, shrink).translated(0, offset * pos.height)
185 else:
186 if aspect:
187 self._cbar.ax.set_box_aspect(1/(aspect * shrink))
188 pos = pos.shrunk(shrink, 1).translated(offset * pos.width, 0)
189 return pos
190
191 def get_subplotspec(self):
192 # make tight_layout happy..
193 return (
194 self._cbar.ax.get_subplotspec()
195 or getattr(self._orig_locator, "get_subplotspec", lambda: None)())
196
197
198def _remove_cbar_axes(ax, cbar):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…