- 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
Plotting an imshow() image in 3d in Matplotlib
To plot an imshow() image in 3D in Matplotlib, we can take the following steps −
Create xx and yy data points using numpy.
Get the data (2D) using X, Y and Z.
Create a new figure or activate an existing figure using figure() method.
Add an 'ax1' to the figure as part of a subplot arrangement.
Display the data as an image, i.e., on a 2D regular raster with data.
Add an 'ax2' to the figure as part of a subplot arrangement.
Create and store a set of contour lines or filled regions.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np from matplotlib import cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xx, yy = np.meshgrid(np.linspace(0, 1, 10), np.linspace(0, 1, 10)) X = xx Y = yy Z = 10 * np.ones(X.shape) data = np.cos(xx) * np.cos(xx) + np.sin(yy) * np.sin(yy) fig = plt.figure() ax1 = fig.add_subplot(121) ax1.imshow(data, cmap="plasma", interpolation='nearest', origin='lower', extent=[0, 1, 0, 1]) ax2 = fig.add_subplot(122, projection='3d') ax2.contourf(X, Y, data, 100, zdir='z', offset=0.5, cmap="plasma") plt.show()
Output
- Related Articles
- Plotting a 3d cube, a sphere and a vector in Matplotlib
- Plotting a 3D surface from a list of tuples in matplotlib?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How to change the scale of imshow in matplotlib without stretching the image?
- Adjusting gridlines and ticks in Matplotlib imshow
- Plotting solar image in Python
- Plotting at full resolution with matplotlib.pyplot, imshow() and savefig()
- How to add legend to imshow() in Matplotlib?
- Defining a discrete colormap for imshow in Matplotlib
- Plotting power spectral density in Matplotlib
- Plotting profile histograms in Python Matplotlib
- Plotting regression and residual plot in Matplotlib
- Plotting animated quivers in Python using Matplotlib
- Plotting histograms against classes in Pandas / Matplotlib
- Plotting distance arrows in technical drawing in Matplotlib

Advertisements