

.. _sphx_glr_gallery_pylab_examples_patheffect_demo.py:


===============
Patheffect Demo
===============





.. image:: /gallery/pylab_examples/images/sphx_glr_patheffect_demo_001.png
    :align: center





.. code-block:: python

    import matplotlib.pyplot as plt
    import matplotlib.patheffects as PathEffects
    import numpy as np

    if 1:
        plt.figure(1, figsize=(8, 3))
        ax1 = plt.subplot(131)
        ax1.imshow([[1, 2], [2, 3]])
        txt = ax1.annotate("test", (1., 1.), (0., 0),
                           arrowprops=dict(arrowstyle="->",
                                           connectionstyle="angle3", lw=2),
                           size=20, ha="center", path_effects=[PathEffects.withStroke(linewidth=3,
                                                                                      foreground="w")])
        txt.arrow_patch.set_path_effects([
            PathEffects.Stroke(linewidth=5, foreground="w"),
            PathEffects.Normal()])

        ax1.grid(True, linestyle="-")

        pe = [PathEffects.withStroke(linewidth=3,
                                     foreground="w")]
        for l in ax1.get_xgridlines() + ax1.get_ygridlines():
            l.set_path_effects(pe)

        ax2 = plt.subplot(132)
        arr = np.arange(25).reshape((5, 5))
        ax2.imshow(arr)
        cntr = ax2.contour(arr, colors="k")

        plt.setp(cntr.collections, path_effects=[
            PathEffects.withStroke(linewidth=3, foreground="w")])

        clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
        plt.setp(clbls, path_effects=[
            PathEffects.withStroke(linewidth=3, foreground="w")])

        # shadow as a path effect
        ax3 = plt.subplot(133)
        p1, = ax3.plot([0, 1], [0, 1])
        leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc=2)
        leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()])

        plt.show()

**Total running time of the script:** ( 0 minutes  0.092 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: patheffect_demo.py <patheffect_demo.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: patheffect_demo.ipynb <patheffect_demo.ipynb>`

.. rst-class:: sphx-glr-signature

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
