- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 two different colored colormaps in the same imshow Matplotlib?
To show two different colored colormaps in the same imshow matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Make a 2D matrix of 5×5 dimension.
Get masked matrix, data1 and data2, with positive and negative values.
Create a figure and a set of subplots.
Display the data as an image, i.e., on a 2D regular raster, with data1 and data2.
To make two different colorbars, use colorbar method.
Set the colorbar for both the images.
Set the label of the colorbars.
To display the figure, use show() method.
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = np.random.randint(-10, 10, (5, 5)) data1 = np.ma.masked_array(img, img >= 0) data2 = np.ma.masked_array(img, img < 0) fig, ax = plt.subplots() img1 = ax.imshow(data1, cmap="prism_r") img2 = ax.imshow(data2, cmap="copper") bar1 = plt.colorbar(img1) bar2 = plt.colorbar(img2) bar1.set_label('ColorBar 1') bar2.set_label('ColorBar 2') plt.show()
- Set two Matplotlib imshow plots to have the same colormap scale
- How to show two figures using Matplotlib?
- How to view all colormaps available in Matplotlib?
- How to show an image in Matplotlib in different colors with different channels?
- How to name different lines in the same plot of Matplotlib?
- How to make Two activities with different colored status bar in Android.
- How to add legend to imshow() in Matplotlib?
- Using Colormaps to set the color of line in Matplotlib
- How to customize the color and colormaps of a Plot in Matplotlib
- How to get different font sizes in the same annotation of Matplotlib?
- How to show a bar and line graph on the same plot in Matplotlib?
- How to apply a mask on the matrix in Matplotlib imshow?
- How to make two histograms have the same bin width in Matplotlib?
- How to show Matplotlib in Flask?
- Plotting two different arrays of different lengths in matplotlib