- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 show an image in Matplotlib in different colors with different channels?
To slice an image into Red, Green and Blue channels with misc.imread, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Read an image from a file into an array.
- Make lists of colormaps and titles.
- Create a figure and a set of subplots.
- Zip the axes, images, titles and colormaps.
- Iterate zipped objs and set the title of each channel image.
- To display the figure, use show() method.
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True image = plt.imread('bird.png') titles = ['With red channel', 'With green channel', 'With blue channel'] cmaps = [plt.cm.Reds_r, plt.cm.Greens_r, plt.cm.Blues_r] fig, axes = plt.subplots(1, 3) objs = zip(axes, (image, *image.transpose(2, 0, 1)), titles, cmaps) for ax, channel, title, cmap in objs: ax.imshow(channel, cmap=cmap) ax.set_title(title) ax.set_xticks(()) ax.set_yticks(()) plt.show()
- Related Articles
- How to split an image into different color channels in OpenCV Python?
- How to specify different colors for different bars in a Python matplotlib histogram?
- How to plot histograms of different colors of an image in OpenCV Python?
- Plot different colors for different categorical levels using matplotlib
- Setting different error bar colors in barplot in Matplotlib
- How to show different colors for points and line in a Seaborn regplot?
- How to display legend in base R with different colors?
- Why different flowers bear different colors?
- How to plot with different scales in Matplotlib?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to show two different colored colormaps in the same imshow Matplotlib?
- How to split images into different channels in OpenCV using C++?
- How to create density plot for categories filled with different colors in R?
- How to create horizontal lines with two different colors after a threshold in R?
- Multiple axes in Matplotlib with different scales