.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/lollipop_plot.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_lollipop_plot.py: ================= f. lollipop_plot ================= .. currentmodule:: easy_mpl This file shows the usage of :func:`lollipop_plot` function. .. GENERATED FROM PYTHON SOURCE LINES 9-18 .. code-block:: Python # sphinx_gallery_thumbnail_number = -1 import matplotlib.pyplot as plt import numpy as np from easy_mpl import lollipop_plot from easy_mpl.utils import version_info version_info() .. rst-class:: sphx-glr-script-out .. code-block:: none {'easy_mpl': '0.21.5', 'matplotlib': '3.9.4', 'numpy': '2.0.2', 'pandas': '2.2.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 19-20 To draw a lollipop we need an array or a list of numeric values .. GENERATED FROM PYTHON SOURCE LINES 20-25 .. code-block:: Python y = np.random.randint(1, 10, size=10) _ = lollipop_plot(y, title="vanilla") .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_001.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_001.png, /auto_examples/images/sphx_glr_lollipop_plot_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 26-27 We can also specify the x coordinates for our data as second argument .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python _ = lollipop_plot(y, np.linspace(0, 100, len(y)), title="with x and y") .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_002.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_002.png, /auto_examples/images/sphx_glr_lollipop_plot_002_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 31-32 line style can be set using ``line_style`` argument. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: Python _ = lollipop_plot(y, line_style='--', title="with custom linestyle") .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_003.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_003.png, /auto_examples/images/sphx_glr_lollipop_plot_003_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-37 Similarly marker style can be set using ``marker_style`` argument. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python _ = lollipop_plot(y, marker_style='D', marker_kws=dict(edgecolor="orange", linewidth=2)) .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_004.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_004.png, /auto_examples/images/sphx_glr_lollipop_plot_004_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 42-43 the line color can also be a matplotlib colormap name .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python _ = lollipop_plot(y, line_color="RdBu") .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_005.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_005.png, /auto_examples/images/sphx_glr_lollipop_plot_005_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-48 We can sort the lollipops by setting the ``sort`` to True .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: Python _ = lollipop_plot(y, sort=True, title="sort") .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_006.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_006.png, /auto_examples/images/sphx_glr_lollipop_plot_006_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 The orientation of lollipops can be made horizontal .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python y = np.random.randint(0, 20, size=10) _ = lollipop_plot(y, orientation="horizontal", title="horizontal") .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_007.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_007.png, /auto_examples/images/sphx_glr_lollipop_plot_007_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-60 The lollipop plot returns matplotlib axes object which can be used for further manipulation of axes. .. GENERATED FROM PYTHON SOURCE LINES 60-69 .. code-block:: Python y = np.random.randint(-10, 10, 20) y[y==0] = 1 ax = lollipop_plot(y, marker_color="#D7BFA6", line_color="burlywood", show=False) ax.axhline(0.0, lw=2.0, color='maroon') ax.axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_lollipop_plot_008.png :alt: lollipop plot :srcset: /auto_examples/images/sphx_glr_lollipop_plot_008.png, /auto_examples/images/sphx_glr_lollipop_plot_008_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.812 seconds) .. _sphx_glr_download_auto_examples_lollipop_plot.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/lollipop_plot.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: lollipop_plot.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: lollipop_plot.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: lollipop_plot.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_