
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/shapes_and_collections/hatch_demo.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_shapes_and_collections_hatch_demo.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_shapes_and_collections_hatch_demo.py:


==========
Hatch demo
==========

Hatches can be added to most polygons in Matplotlib, including `~.Axes.bar`,
`~.Axes.fill_between`, `~.Axes.contourf`, and children of `~.patches.Polygon`.
They are currently supported in the PS, PDF, SVG, macosx, and Agg backends. The WX
and Cairo backends do not currently support hatching.

See also :doc:`/gallery/images_contours_and_fields/contourf_hatching` for
an example using `~.Axes.contourf`, and
:doc:`/gallery/shapes_and_collections/hatch_style_reference` for swatches
of the existing hatches.

.. GENERATED FROM PYTHON SOURCE LINES 17-49

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.patches import Ellipse, Polygon

    x = np.arange(1, 5)
    y1 = np.arange(1, 5)
    y2 = np.ones(y1.shape) * 4

    fig = plt.figure()
    axs = fig.subplot_mosaic([['bar1', 'patches'], ['bar2', 'patches']])

    axs['bar1'].bar(x, y1, edgecolor='black', hatch="/")
    axs['bar1'].bar(x, y2, bottom=y1, edgecolor='black', hatch='//')

    axs['bar2'].bar(x, y1, edgecolor='black', hatch=['--', '+', 'x', '\\'])
    axs['bar2'].bar(x, y2, bottom=y1, edgecolor='black',
                    hatch=['*', 'o', 'O', '.'])

    x = np.arange(0, 40, 0.2)
    axs['patches'].fill_between(x, np.sin(x) * 4 + 30, y2=0,
                                hatch='///', zorder=2, fc='c')
    axs['patches'].add_patch(Ellipse((4, 50), 10, 10, fill=True,
                                     hatch='*', facecolor='y'))
    axs['patches'].add_patch(Polygon([(10, 20), (30, 50), (50, 10)],
                                     hatch='\\/...', facecolor='g'))
    axs['patches'].set_xlim([0, 40])
    axs['patches'].set_ylim([10, 60])
    axs['patches'].set_aspect(1)
    plt.show()




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_hatch_demo_001.png
   :alt: hatch demo
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_hatch_demo_001.png, /gallery/shapes_and_collections/images/sphx_glr_hatch_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 50-61

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.patches`
   - `matplotlib.patches.Ellipse`
   - `matplotlib.patches.Polygon`
   - `matplotlib.axes.Axes.add_patch`
   - `matplotlib.patches.Patch.set_hatch`
   - `matplotlib.axes.Axes.bar` / `matplotlib.pyplot.bar`


.. _sphx_glr_download_gallery_shapes_and_collections_hatch_demo.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

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

    .. container:: sphx-glr-download sphx-glr-download-python

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: hatch_demo.zip <hatch_demo.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
