A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/matplotlib-pyplot-stem-in-python/ below:

Matplotlib.pyplot.stem() in Python - GeeksforGeeks

Matplotlib.pyplot.stem() in Python

Last Updated : 12 Jul, 2025

Matplotlib

is a visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.

matplotlib.pyplot.stem()matplotlib.pyplot.stem()

creates stem plots. A

Stem plot

plots vertical lines at each x position covered under the graph from the baseline to y, and places a marker there.

Syntax: stem([x, ] y, linefmt=None, markerfmt=None, basefmt=None) Parameters: Returns :
container: StemContainer

The container may be treated like a tuple (markerline, stemlines, baseline)

Example #1:

Default plot Stem plots vertical lines from a baseline to the y-coordinate and places a marker at the tip.

Python3
# importing libraries
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))

plt.stem(x, y, use_line_collection = True)
plt.show()
Output :   Example #2:

The position of the baseline can be adapted using

bottom

. The parameters

linefmt, markerfmt

, and

basefmt

control basic format properties of the plot. However, in contrast to

plot

not all properties are configurable via keyword arguments. For more advanced control adapt the line objects returned by

pyplot

.

Python
# importing libraries
import random
import matplotlib.pyplot as plt

x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))

markerline, stemlines, baseline = plt.stem(
    x, y, linefmt ='grey', markerfmt ='D',
    bottom = 1.1, use_line_collection = True)

markerline.set_markerfacecolor('none')
plt.show()
Output:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4