Displaying images with other plots in the figure
This recipe will show how we can make simple yet effective usage of Python matplotlib library to process image channels and display the per-channel histogram of an external image.
Getting ready
We have provided some sample images, but the code is ready to load any image file, provided it is supported by matplotlib's imread
function.
In this recipe, you will learn how to combine different matplotlib plots to achieve functionality of a simple image viewer that displays an image histogram for red, green, and blue channels.
How to do it...
To show how to build an image histogram viewer, we are going to implement a simple class named ImageViewer
, and that class will contain helper methods to:
- Load image.
Get Python Data Visualization Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.