.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ex1.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_ex1.py: ==================== Simple patheffect example ==================== .. GENERATED FROM PYTHON SOURCE LINES 7-47 .. image-sg:: /examples/images/sphx_glr_ex1_001.png :alt: ex1 :srcset: /examples/images/sphx_glr_ex1_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import mpl_visual_context.patheffects as pe from matplotlib.transforms import Affine2D from mpl_skia_pathops import PathOpsPathEffect # from mpl_skia_pathops import PathOps fig, axs = plt.subplots(2, 1, num=1, clear=True) ax = axs[0] t = ax.text(0.5, 0.5, "Matplotib", size=50, ha="center", va="center") t.set_bbox(dict(facecolor='none', ec="none")) def bbox(): return t.get_bbox_patch() t.set_path_effects([PathOpsPathEffect.difference(bbox, invert=True) | pe.Gradient("right")]) ax = axs[1] t2 = ax.text(0.5, 0.5, "Matplotib", size=50, ha="center", va="center") t2.set_bbox(dict(facecolor='none', ec="none")) def bbox_half(): "we get the rectangle that spans the bottom half of the text bbox" p = t2.get_bbox_patch() path = p.get_path() ymin = path.vertices[: -1].min() affine = Affine2D().translate(0, -ymin).scale(1, 0.5).translate(0, ymin) tr = p.get_transform() return (affine + tr).transform_path(path) t2.set_path_effects([PathOpsPathEffect.xor(bbox_half, invert=True) | pe.Gradient("right")]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.118 seconds) .. _sphx_glr_download_examples_ex1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex1.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_