

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How to plot an animated image matrix in matplotlib?
- Plot a vector field over the axes in Python Matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to plot a watermark image in Matplotlib?
- How to apply pseudo color schemes to an image plot in Matplotlib?
- Gaussian filtering an image with NaN in Python Matplotlib
- How to plot an array in Python using Matplotlib?
- Flip an image on mouse over with CSS
- How to plot an angle spectrum using Matplotlib in Python?
- CSS background-image property
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How to a plot stem plot in Matplotlib Python?
- Set the background image of an element with CSS
- Turn an image into a Bootstrap 4 card background
- How to remove grid lines from an image in Python Matplotlib?
Advertisements