Matplotlib.axes.Axes.stem() in Python

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


Output:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.