
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/misc/contour_manual.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_misc_contour_manual.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_misc_contour_manual.py:


==============
Manual Contour
==============

Example of displaying your own contour lines and polygons using ContourSet.

.. GENERATED FROM PYTHON SOURCE LINES 8-15

.. code-block:: Python


    import matplotlib.pyplot as plt

    import matplotlib.cm as cm
    from matplotlib.contour import ContourSet
    from matplotlib.path import Path








.. GENERATED FROM PYTHON SOURCE LINES 16-17

Contour lines for each level are a list/tuple of polygons.

.. GENERATED FROM PYTHON SOURCE LINES 17-21

.. code-block:: Python

    lines0 = [[[0, 0], [0, 4]]]
    lines1 = [[[2, 0], [1, 2], [1, 3]]]
    lines2 = [[[3, 0], [3, 2]], [[3, 3], [3, 4]]]  # Note two lines.








.. GENERATED FROM PYTHON SOURCE LINES 22-24

Filled contours between two levels are also a list/tuple of polygons.
Points can be ordered clockwise or anticlockwise.

.. GENERATED FROM PYTHON SOURCE LINES 24-28

.. code-block:: Python

    filled01 = [[[0, 0], [0, 4], [1, 3], [1, 2], [2, 0]]]
    filled12 = [[[2, 0], [3, 0], [3, 2], [1, 3], [1, 2]],   # Note two polygons.
                [[1, 4], [3, 4], [3, 3]]]








.. GENERATED FROM PYTHON SOURCE LINES 29-44

.. code-block:: Python


    fig, ax = plt.subplots()

    # Filled contours using filled=True.
    cs = ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone)
    cbar = fig.colorbar(cs)

    # Contour lines (non-filled).
    lines = ContourSet(
        ax, [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool, linewidths=3)
    cbar.add_lines(lines)

    ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 4.5),
           title='User-specified contours')




.. image-sg:: /gallery/misc/images/sphx_glr_contour_manual_001.png
   :alt: User-specified contours
   :srcset: /gallery/misc/images/sphx_glr_contour_manual_001.png, /gallery/misc/images/sphx_glr_contour_manual_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 45-48

Multiple filled contour lines can be specified in a single list of polygon
vertices along with a list of vertex kinds (code types) as described in the
Path class.  This is particularly useful for polygons with holes.

.. GENERATED FROM PYTHON SOURCE LINES 48-61

.. code-block:: Python


    fig, ax = plt.subplots()
    filled01 = [[[0, 0], [3, 0], [3, 3], [0, 3], [1, 1], [1, 2], [2, 2], [2, 1]]]
    M = Path.MOVETO
    L = Path.LINETO
    kinds01 = [[M, L, L, L, M, L, L, L]]
    cs = ContourSet(ax, [0, 1], [filled01], [kinds01], filled=True)
    cbar = fig.colorbar(cs)

    ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 3.5),
           title='User specified filled contours with holes')

    plt.show()



.. image-sg:: /gallery/misc/images/sphx_glr_contour_manual_002.png
   :alt: User specified filled contours with holes
   :srcset: /gallery/misc/images/sphx_glr_contour_manual_002.png, /gallery/misc/images/sphx_glr_contour_manual_002_2_00x.png 2.00x
   :class: sphx-glr-single-img






.. _sphx_glr_download_gallery_misc_contour_manual.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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