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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_shapes_and_collections_hatch_style_reference.py>`
        to download the full example code

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

.. _sphx_glr_gallery_shapes_and_collections_hatch_style_reference.py:


=====================
Hatch style reference
=====================

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, OSX, 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_demo` for more usage examples.

.. GENERATED FROM PYTHON SOURCE LINES 16-33

.. code-block:: default

    import matplotlib.pyplot as plt
    from matplotlib.patches import Rectangle

    fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(6.4, 3.2))

    hatches = ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']


    def hatches_plot(ax, h):
        ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h))
        ax.text(1, -0.5, f"' {h} '", size=15, ha="center")
        ax.axis('equal')
        ax.axis('off')

    for ax, h in zip(axs.flat, hatches):
        hatches_plot(ax, h)




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_001.png
   :alt: hatch style reference
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_001.png, /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_001_2_0x.png 2.0x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 34-35

Hatching patterns can be repeated to increase the density.

.. GENERATED FROM PYTHON SOURCE LINES 35-43

.. code-block:: default


    fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(6.4, 3.2))

    hatches = ['//', '\\\\', '||', '--', '++', 'xx', 'oo', 'OO', '..', '**']

    for ax, h in zip(axs.flat, hatches):
        hatches_plot(ax, h)




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_002.png
   :alt: hatch style reference
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_002.png, /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_002_2_0x.png 2.0x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 44-45

Hatching patterns can be combined to create additional patterns.

.. GENERATED FROM PYTHON SOURCE LINES 45-53

.. code-block:: default


    fig, axs = plt.subplots(2, 5, constrained_layout=True, figsize=(6.4, 3.2))

    hatches = ['/o', '\\|', '|*', '-\\', '+o', 'x*', 'o-', 'O|', 'O.', '*-']

    for ax, h in zip(axs.flat, hatches):
        hatches_plot(ax, h)




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_003.png
   :alt: hatch style reference
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_003.png, /gallery/shapes_and_collections/images/sphx_glr_hatch_style_reference_003_2_0x.png 2.0x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 54-63

.. admonition:: References

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

   - `matplotlib.patches`
   - `matplotlib.patches.Rectangle`
   - `matplotlib.axes.Axes.add_patch`
   - `matplotlib.axes.Axes.text`


.. _sphx_glr_download_gallery_shapes_and_collections_hatch_style_reference.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
