- 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
Plot a black-and-white binary map in Matplotlib
To plot black-and-white binary map in matplotlib, we can create and add two subplots to the current figure using subplot() method, where nrows=1 and ncols=2. To display the data as a binary map, we can use greys colormap in imshow() method.
Steps
- Create data using numpy
- Add two sublots, nrows=1 and ncols=2. Consider index 1.
- To show colored image, use imshow() method.
- Add title to the colored map.
- Add a second subplot at index 2.
- To show the binary map, use show() method with Greys colormap.
- To adjust the padding between and around the subplots, use tight_layout() method.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(4, 4) plt.subplot(121) plt.imshow(data) plt.title("Colored Image") plt.subplot(122) plt.imshow(data, cmap='Greys_r', interpolation='nearest') plt.title("Greys Image") plt.tight_layout() plt.show()
Output
- Related Articles
- How to plot a half-black and half-white circle using Matplotlib?
- How to plot a density map in Python Matplotlib?
- How to plot Time Zones in a map in Matplotlib
- How to plot a 3D density map in Python with Matplotlib?
- How to create a black and white word cloud in R?
- How to create a "black and white" image with CSS?
- How to Create a Black and White Image Using CSS
- How to change the plot line color from blue to black in Matplotlib?
- Layering a contourf plot and surface_plot in Matplotlib
- How to create a black image and a white image using OpenCV Python?
- Why do doctors wear White & Lawyers black?
- A bag contains 15 white and some black balls. If the probability of drawing a black ball from the bag is thrice that of drawing a white ball, find the number of black balls in the bag.
- How to a plot stem plot in Matplotlib Python?
- Map values to colors in Matplotlib
- Plotting regression and residual plot in Matplotlib

Advertisements