Open In App

Matplotlib.axes.Axes.stem() in Python

Last Updated : 13 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.stem() Function

The Axes.stem() function in axes module of matplotlib library is used to create a stem plot.
Syntax: Axes.stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, label=None, use_line_collection=False, data=None) Parameters: This method accept the following parameters that are described below:
  • x: This parameter is the sequence of x coordinates of the stems.
  • y: This parameter is the sequence of y coordinates of the stem heads.
  • linefmt: This parameter is the string defining the properties of the vertical lines.
  • markerfmt: This parameter is the string defining the properties of the markers at the stem heads.
  • basefmt: This parameter is the string defining the properties of the baseline.
  • bottom: This parameter is the y-position of the baseline.
  • label: This parameter is the label to use for the stems in legends.
Returns: This returns the following:
  • StemContainer: This returns the container which may be treated like a tuple (markerline, stemlines, baseline).
Below examples illustrate the matplotlib.axes.Axes.broken_barh() function in matplotlib.axes: Example-1: Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.stem([0.3, 1.5, 2.7], 
        [1, 3.6, 2.7], 
        label ="stem test")

ax.legend()
ax.set_title('matplotlib.axes.Axes.stem Example')
plt.show()
Output: Example-2: Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np

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

fig, ax = plt.subplots()

ax.stem(x, y, linefmt ='grey', 
        markerfmt ='D', 
        bottom = 1.1, 
        use_line_collection = True)

ax.set_title('matplotlib.axes.Axes.stem Example')
plt.show()

Next Article
Article Tags :
Practice Tags :

Similar Reads