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

.. only:: html

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

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

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

.. _sphx_glr_gallery_showcase_xkcd.py:


====
XKCD
====

Shows how to create an xkcd-like plot.

.. GENERATED FROM PYTHON SOURCE LINES 8-11

.. code-block:: default

    import matplotlib.pyplot as plt
    import numpy as np








.. GENERATED FROM PYTHON SOURCE LINES 12-41

.. code-block:: default


    with plt.xkcd():
        # Based on "Stove Ownership" from XKCD by Randall Munroe
        # https://xkcd.com/418/

        fig = plt.figure()
        ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
        ax.spines['right'].set_color('none')
        ax.spines['top'].set_color('none')
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_ylim([-30, 10])

        data = np.ones(100)
        data[70:] -= np.arange(30)

        ax.annotate(
            'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED',
            xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10))

        ax.plot(data)

        ax.set_xlabel('time')
        ax.set_ylabel('my overall health')
        fig.text(
            0.5, 0.05,
            '"Stove Ownership" from xkcd by Randall Munroe',
            ha='center')




.. image:: /gallery/showcase/images/sphx_glr_xkcd_001.png
    :alt: xkcd
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 42-67

.. code-block:: default


    with plt.xkcd():
        # Based on "The Data So Far" from XKCD by Randall Munroe
        # https://xkcd.com/373/

        fig = plt.figure()
        ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
        ax.bar([0, 1], [0, 100], 0.25)
        ax.spines['right'].set_color('none')
        ax.spines['top'].set_color('none')
        ax.xaxis.set_ticks_position('bottom')
        ax.set_xticks([0, 1])
        ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])
        ax.set_xlim([-0.5, 1.5])
        ax.set_yticks([])
        ax.set_ylim([0, 110])

        ax.set_title("CLAIMS OF SUPERNATURAL POWERS")

        fig.text(
            0.5, 0.05,
            '"The Data So Far" from xkcd by Randall Munroe',
            ha='center')

    plt.show()



.. image:: /gallery/showcase/images/sphx_glr_xkcd_002.png
    :alt: CLAIMS OF SUPERNATURAL POWERS
    :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_gallery_showcase_xkcd.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: xkcd.py <xkcd.py>`



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

     :download:`Download Jupyter notebook: xkcd.ipynb <xkcd.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>`_
