- 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
How to create a surface plot from a greyscale image with Matplotlib?
To create a surface plot from a grayscale image with matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create random data points using Numpy.
Get the xx and yy data points from a 2d image data raster.
Create a new figure or activate an existing figure.
Get the current axis of the plot and make it 3d projection axes.
Create a surface plot with cmap='gray'.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) xx, yy = np.mgrid[0:data.shape[0], 0:data.shape[1]] fig = plt.figure() ax = fig.gca(projection='3d') ax.plot_surface(xx, yy, data, rstride=1, cstride=1, linewidth=0, cmap='gray') plt.show()
Output
- Related Articles
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to create a Swarm Plot with Matplotlib?
- How to plot a remote image from http url using Matplotlib?
- How to plot a watermark image in Matplotlib?
- How to insert a small image on the corner of a plot with Matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to use a custom png image marker in a plot (Matplotlib)?
- How to extract data from a Matplotlib plot?
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- How to create custom markers on a plot in Matplotlib
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot a smooth line with matplotlib?
- How to change an image to greyscale in Node Jimp?
- How to create minor ticks for a polar plot in matplotlib?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?

Advertisements