- 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
Defining the midpoint of a colormap in Matplotlib
Using plt.subplots(1, 1) method, we can create fig and axis. We can use fig.colorbar to make the color bar at the midpoint of the figure.
Steps
Using mgrid() method, `nd_grid` instance which returns an open multi-dimensional "meshgrid".
Create Z1, Z2 and Z data.
Create fig and ax variables using subplots method, where default nrows and ncols are 1, using subplots() method.
Create a colorbar for a ScalarMappable instance, *mappable*, using colorbar() method.
Using plt.show(), we can show the figure.
Example
import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as colors N = 100 X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] Z1 = np.exp(-(X)**2 - (Y)**2) Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) Z = Z1 + 50 * Z2 fig, ax = plt.subplots(1, 1) fig.colorbar(ax.pcolor(X, Y, Z, norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()), shading='auto')) plt.show()
Output
- Related Articles
- Defining a discrete colormap for imshow in Matplotlib
- How to extract a subset of a colormap as a new colormap in Matplotlib?
- Set a colormap of an image in Matplotlib
- How to set a default colormap in Matplotlib?
- Extract Matplotlib colormap in hex-format
- How to make the Parula colormap in Matplotlib?
- Plot a histogram with colors taken from colormap in Matplotlib
- How to draw node colormap in NetworkX/Matplotlib?
- How to display the matrix value and colormap in Matplotlib?
- Matplotlib Plot Lines with Colors through Colormap
- Add alpha to an existing Matplotlib colormap
- How to increase colormap/linewidth quality in streamplot Matplotlib?
- How to shade points in a scatter based on colormap in Matplotlib?
- How to redefine a color for a specific value in a Matplotlib colormap?
- 3D scatterplots in Python Matplotlib with hue colormap and legend

Advertisements