- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Python - Working with PNG Images using Matplotlib
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
Example
#applying pseudocolor # importing pyplot and image from matplotlib import matplotlib.pyplot as plt import matplotlib.image as img # reading png image im = img.imread('imR.png') # applying pseudocolor # default value of colormap is used. lum = im[:, :, 0] # show image plt.imshow(lum) #colorbar # importing pyplot and image from matplotlib import matplotlib.pyplot as plt import matplotlib.image as img # reading png image im = img.imread('imR.png') lum = im[:, :, 0] # setting colormap as hot plt.imshow(lum, cmap ='hot') plt.colorbar() #interpolation # importing PIL and matplotlib from PIL import Image import matplotlib.pyplot as plt # reading png image file img = Image.open('imR.png') # resizing the image img.thumbnail((50, 50), Image.ANTIALIAS) imgplot = plt.imshow(img) #bicubic value for interpolation # importing pyplot from matplotlib import matplotlib.pyplot as plt # importing image from PIL from PIL import Image # reading image img = Image.open('imR.png') img.thumbnail((30, 30), Image.ANTIALIAS) # bicubic used for interpolation imgplot = plt.imshow(img, interpolation ='bicubic')#sinc value for interpolation # sinc value for interpolation # importing PIL and matplotlib from PIL import Image import matplotlib.pyplot as plt # reading image img = Image.open('imR.png') img.thumbnail((30, 30), Image.ANTIALIAS) # sinc used for interpolation imgplot = plt.imshow(img, interpolation ='sinc')
- Related Articles
- Working with Images in Python?
- Reading images using Python?
- How to optimize and compress jpeg or png images in linux
- How to display a sequence of images using Matplotlib?
- Python - Display images with PyGame
- Displaying different images with actual size in a Matplotlib subplot
- Python Grayscaling of Images using OpenCV
- How to download Google Images using Python
- Using WebP Images with Fallback in CSS
- Python - Working with .docx module
- Arithmetic Operations on Images using OpenCV in Python
- How to use a custom png image marker in a plot (Matplotlib)?
- Working with PDF files in Python?
- Working with zip files in Python
- Python - Working with buttons in Kivy

Advertisements