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

Method _do_extends

lib/matplotlib/colorbar.py:659–751  ·  view source on GitHub ↗

Add the extend tri/rectangles on the outside of the Axes. ax is unused, but required due to the callbacks on xlim/ylim changed

(self, ax=None)

Source from the content-addressed store, hash-verified

657 self.solids_patches = patches
658
659 def _do_extends(self, ax=None):
660 """
661 Add the extend tri/rectangles on the outside of the Axes.
662
663 ax is unused, but required due to the callbacks on xlim/ylim changed
664 """
665 # Clean up any previous extend patches
666 for patch in self._extend_patches:
667 patch.remove()
668 self._extend_patches = []
669 # extend lengths are fraction of the *inner* part of colorbar,
670 # not the total colorbar:
671 _, extendlen = self._proportional_y()
672 bot = 0 - (extendlen[0] if self._extend_lower() else 0)
673 top = 1 + (extendlen[1] if self._extend_upper() else 0)
674
675 # xyout is the outline of the colorbar including the extend patches:
676 if not self.extendrect:
677 # triangle:
678 xyout = np.array([[0, 0], [0.5, bot], [1, 0],
679 [1, 1], [0.5, top], [0, 1], [0, 0]])
680 else:
681 # rectangle:
682 xyout = np.array([[0, 0], [0, bot], [1, bot], [1, 0],
683 [1, 1], [1, top], [0, top], [0, 1],
684 [0, 0]])
685
686 if self.orientation == 'horizontal':
687 xyout = xyout[:, ::-1]
688
689 # xyout is the path for the spine:
690 self.outline.set_xy(xyout)
691 if not self._filled:
692 return
693
694 # Make extend triangles or rectangles filled patches. These are
695 # defined in the outer parent axes' coordinates:
696 mappable = getattr(self, 'mappable', None)
697 if (isinstance(mappable, contour.ContourSet)
698 and any(hatch is not None for hatch in mappable.hatches)):
699 hatches = mappable.hatches * (len(self._y) + 1)
700 else:
701 hatches = [None] * (len(self._y) + 1)
702
703 if self._extend_lower():
704 if not self.extendrect:
705 # triangle
706 xy = np.array([[0, 0], [0.5, bot], [1, 0]])
707 else:
708 # rectangle
709 xy = np.array([[0, 0], [0, bot], [1., bot], [1, 0]])
710 if self.orientation == 'horizontal':
711 xy = xy[:, ::-1]
712 # add the patch
713 val = -1 if self.long_axis.get_inverted() else 0
714 color = self.cmap(self.norm(self._values[val]))
715 patch = mpatches.PathPatch(
716 mpath.Path(xy), facecolor=color, alpha=self.alpha,

Callers 1

_draw_allMethod · 0.95

Calls 10

_proportional_yMethod · 0.95
_extend_lowerMethod · 0.95
_extend_upperMethod · 0.95
_update_dividersMethod · 0.95
get_invertedMethod · 0.80
add_patchMethod · 0.80
removeMethod · 0.45
set_xyMethod · 0.45
cmapMethod · 0.45
normMethod · 0.45

Tested by

no test coverage detected