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

Class Shadow

lib/matplotlib/patches.py:766–823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764
765
766class Shadow(Patch):
767 def __str__(self):
768 return f"Shadow({self.patch})"
769
770 @_docstring.interpd
771 def __init__(self, patch, ox, oy, *, shade=0.7, **kwargs):
772 """
773 Create a shadow of the given *patch*.
774
775 By default, the shadow will have the same face color as the *patch*,
776 but darkened. The darkness can be controlled by *shade*.
777
778 Parameters
779 ----------
780 patch : `~matplotlib.patches.Patch`
781 The patch to create the shadow for.
782 ox, oy : float
783 The shift of the shadow in data coordinates, scaled by a factor
784 of dpi/72.
785 shade : float, default: 0.7
786 How the darkness of the shadow relates to the original color. If 1, the
787 shadow is black, if 0, the shadow has the same color as the *patch*.
788
789 .. versionadded:: 3.8
790
791 **kwargs
792 Properties of the shadow patch. Supported keys are:
793
794 %(Patch:kwdoc)s
795 """
796 super().__init__()
797 self.patch = patch
798 self._ox, self._oy = ox, oy
799 self._shadow_transform = transforms.Affine2D()
800
801 self.update_from(self.patch)
802 if not 0 <= shade <= 1:
803 raise ValueError("shade must be between 0 and 1.")
804 color = (1 - shade) * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
805 self.update({'facecolor': color, 'edgecolor': color, 'alpha': 0.5,
806 # Place shadow patch directly behind the inherited patch.
807 'zorder': np.nextafter(self.patch.zorder, -np.inf),
808 **kwargs})
809
810 def _update_transform(self, renderer):
811 ox = renderer.points_to_pixels(self._ox)
812 oy = renderer.points_to_pixels(self._oy)
813 self._shadow_transform.clear().translate(ox, oy)
814
815 def get_path(self):
816 return self.patch.get_path()
817
818 def get_patch_transform(self):
819 return self.patch.get_patch_transform() + self._shadow_transform
820
821 def draw(self, renderer):
822 self._update_transform(renderer)
823 super().draw(renderer)

Callers 3

drawMethod · 0.90
demo_text_path.pyFile · 0.90
svg_filter_pie.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…