mplutils.lollipop#

mplutils.lollipop(x, y, ax=None, base=0.0, **kwargs)[source]#

Draw a lollipop chart on the given axes.

Parameters:
xarray_like

X positions or categorical labels. Non-numeric values are treated as categories and mapped to integer positions.

yarray_like

Y values for each lollipop.

axmatplotlib.axes.Axes, optional.

Target axes to plot on.

If None, use last active axes.

basefloat or array_like, optional

Baseline value(s) from which the vertical lines start. Default is 0.

**kwargs

Additional keyword arguments passed to Axes.plot for marker styling. Common aliases like ms, lw, ls, and c are supported.

Returns:
markersmatplotlib.lines.Line2D

The Line2D object corresponding to the lollipop markers.

linesmatplotlib.collections.LineCollection

The LineCollection corresponding to the lollipop sticks.

Examples

import matplotlib.pyplot as plt

import mplutils as mplu

fig, (ax0, ax1) = plt.subplots(1, 2, layout=mplu.FixedLayoutEngine())

mplu.lollipop(["A", "B", "C"], [1, 2, 3], ax=ax0)
mplu.lollipop([1, 2, 3], [3, 2, 1], ax=ax1, color="r", base=(2, 1, 0))

for ax in (ax0, ax1):
    mplu.set_axes_size(2.5, ax=ax)

(Source code, png, hires.png, pdf)

../../_images/lollipop.png