- 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 use a custom png image marker in a plot (Matplotlib)?
To use custome png or jpg i.e an image as a marker in a plot, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Make a paths list to store the directories of images.
Make a list (x and y) of points.
Using subplots() method, create a figure and a set of subplots.
To plot images instead of points, iterate zipped x, y and paths.
Instantiate AnnotationBbox() with image and (x, y) points.
Put xticks and yticks on both the axes.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt from matplotlib.offsetbox import OffsetImage, AnnotationBbox plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def getImage(path): return OffsetImage(plt.imread(path, format="jpg"), zoom=.1) paths = ['globe.jpg', 'settings.jpg', 'settings.jpg', 'globe.jpg'] x = [8, 4, 3, 6] y = [5, 3, 4, 7] fig, ax = plt.subplots() for x0, y0, path in zip(x, y, paths): ab = AnnotationBbox(getImage(path), (x0, y0), frameon=False) ax.add_artist(ab) plt.xticks(range(10)) plt.yticks(range(10)) plt.show()
Output
- Related Articles
- How to plot a watermark image in Matplotlib?
- How to create custom markers on a plot in Matplotlib
- How to plot a layered image in Matplotlib in Python?
- How to use Font Awesome symbol as marker in matplotlib?
- How to plot scatter points with increasing size of marker in Matplotlib?
- How to plot two dotted lines and set marker using Matplotlib?
- Add a custom border to certain cells in a Matplotlib / Seaborn plot
- How to read a JPEG or PNG image in PyTorch?
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- How to create a surface plot from a greyscale image with Matplotlib?
- How to plot a remote image from http url using Matplotlib?
- How to plot data into imshow() with custom colormap in Matplotlib?
- How to draw a png image on a Python tkinter canvas?
- How to plot an animated image matrix in matplotlib?
- How to Adjust Marker Size in Matplotlib?

Advertisements