.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plotting/_lollipop.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` 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_plotting__lollipop.py: ==================== 6.6 lollipop plot ==================== .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: default # 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.4', 'matplotlib': '3.8.4', 'numpy': '1.26.4', 'pandas': '1.5.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 17-18 To draw a lollipop we need an array or a list of numeric values .. GENERATED FROM PYTHON SOURCE LINES 18-23 .. code-block:: default y = np.random.randint(1, 10, size=10) _ = lollipop_plot(y, title="vanilla") .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_001.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_001.png, /auto_examples/plotting/images/sphx_glr__lollipop_001_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 24-25 We can also specify the x coordinates for our data as second argument .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: default _ = lollipop_plot(y, np.linspace(0, 100, len(y)), title="with x and y") .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_002.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_002.png, /auto_examples/plotting/images/sphx_glr__lollipop_002_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-30 line style can be set using ``line_style`` argument. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default _ = lollipop_plot(y, line_style='--', title="with custom linestyle") .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_003.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_003.png, /auto_examples/plotting/images/sphx_glr__lollipop_003_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-35 Similarly marker style can be set using ``marker_style`` argument. .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: default _ = lollipop_plot(y, marker_style='D', marker_kws=dict(edgecolor="orange", linewidth=2)) .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_004.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_004.png, /auto_examples/plotting/images/sphx_glr__lollipop_004_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-41 the line color can also be a matplotlib colormap name .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default _ = lollipop_plot(y, line_color="RdBu") .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_005.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_005.png, /auto_examples/plotting/images/sphx_glr__lollipop_005_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-46 We can sort the lollipops by setting the ``sort`` to True .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: default _ = lollipop_plot(y, sort=True, title="sort") .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_006.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_006.png, /auto_examples/plotting/images/sphx_glr__lollipop_006_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-51 The orientation of lollipops can be made horizontal .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: default y = np.random.randint(0, 20, size=10) _ = lollipop_plot(y, orientation="horizontal", title="horizontal") .. image-sg:: /auto_examples/plotting/images/sphx_glr__lollipop_007.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_007.png, /auto_examples/plotting/images/sphx_glr__lollipop_007_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-58 The lollipop plot returns matplotlib axes object which can be used for further manipulation of axes. .. GENERATED FROM PYTHON SOURCE LINES 58-67 .. code-block:: default 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/plotting/images/sphx_glr__lollipop_008.png :alt: lollipop :srcset: /auto_examples/plotting/images/sphx_glr__lollipop_008.png, /auto_examples/plotting/images/sphx_glr__lollipop_008_2_0x.png 2.0x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.853 seconds) .. _sphx_glr_download_auto_examples_plotting__lollipop.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/AtrCheema/python-seekho/master?urlpath=lab/tree/notebooks/auto_examples/plotting/_lollipop.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _lollipop.py <_lollipop.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _lollipop.ipynb <_lollipop.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_