
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Matplotlib – Plot over an image background in Python
To plot over an image background, we can take the following steps−
- Read an image from a file into an array.
- Create a figure (fig) and add a set of subplots (ax) with extent [0, 300, 0, 300].
- Create an array x of range (300).
- Plot x using plot() method with linestyle=dotted, linewidth=2, and color=red.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True im = plt.imread("bird.jpg") fig, ax = plt.subplots() im = ax.imshow(im, extent=[0, 300, 0, 300]) x = np.array(range(300)) ax.plot(x, x, ls='dotted', linewidth=2, color='red') plt.show()
Output
- Related Articles
- Plot a vector field over the axes in Python Matplotlib?
- How to plot an animated image matrix in matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to apply pseudo color schemes to an image plot in Matplotlib?
- How to plot an array in Python using Matplotlib?
- How to plot a watermark image in Matplotlib?
- How to plot an angle spectrum using Matplotlib in Python?
- Gaussian filtering an image with NaN in Python Matplotlib
- How to a plot stem plot in Matplotlib Python?
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- How to zoom a portion of an image and insert in the same plot in Matplotlib?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How to remove grid lines from an image in Python Matplotlib?
- How to plot signal in Matplotlib in Python?
- How to plot cdf in Matplotlib in Python?

Advertisements