f. lollipop_plot

This file shows the usage of lollipop_plot() function.

# 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()
{'easy_mpl': '0.21.4', 'matplotlib': '3.8.0', 'numpy': '1.26.1', 'pandas': '2.1.1', 'scipy': '1.11.3'}

To draw a lollipop we need an array or a list of numeric values

y = np.random.randint(1, 10, size=10)

_ = lollipop_plot(y, title="vanilla")
lollipop plot

We can also specify the x coordinates for our data as second argument

_ = lollipop_plot(y, np.linspace(0, 100, len(y)), title="with x and y")
lollipop plot

line style can be set using line_style argument.

_ = lollipop_plot(y, line_style='--', title="with custom linestyle")
lollipop plot

Similarly marker style can be set using marker_style argument.

_ = lollipop_plot(y, marker_style='D',
                  marker_kws=dict(edgecolor="orange", linewidth=2))
lollipop plot

the line color can also be a matplotlib colormap name

_ = lollipop_plot(y, line_color="RdBu")
lollipop plot

We can sort the lollipops by setting the sort to True

_ = lollipop_plot(y, sort=True, title="sort")
lollipop plot

The orientation of lollipops can be made horizontal

y = np.random.randint(0, 20, size=10)
_ = lollipop_plot(y, orientation="horizontal", title="horizontal")
lollipop plot

The lollipop plot returns matplotlib axes object which can be used for further manipulation of axes.

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()
lollipop plot

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

Gallery generated by Sphinx-Gallery