
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Insert Small Image on Plot Corner with Matplotlib
To insert a small image on the corner of a plot with matplotlib, we can take the following steps−
- Read an image from a file into an array using imread() method.
- Using subplots() method, create a figure and add a set of subplots.
- Plot a line on the current axis.
- Create newax (new axis) to show the image array (Step 1).
- Turn off the newly created axis, created for an image insert.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True im = plt.imread('bird.jpg') # insert local path of the image. fig, ax = plt.subplots() ax.plot(range(10)) newax = fig.add_axes([0.8,0.8,0.2,0.2], anchor='NE', zorder=1) newax.imshow(im) newax.axis('off') plt.show()
Output
Advertisements