- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to a plot stem plot in Matplotlib Python?
To plot a stem plot in Matplotlib, we can use stem() method. It creates vertical lines from a baseline to the Y-coordinate and places a marker at the tip.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points using numpy.
- Create a stem plot using stem() method.
- Set the marker face color with red color.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True 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='*', bottom=1.1) markerline.set_markerfacecolor('red') plt.show()
Output
- Related Articles
- How to plot a density map in Python Matplotlib?
- How to plot a multivariate function in Python Matplotlib?
- How to plot signal in Matplotlib in Python?
- How to plot cdf in Matplotlib in Python?
- How to plot MFCC in Python using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to plot a phase spectrum in Matplotlib in Python?
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot magnitude spectrum in Matplotlib in Python?
- How to plot a circle in Matplotlib?
- How to plot an array in Python using Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- How to plot a function defined with def in Python? (Matplotlib)

Advertisements