- 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 a masked surface plot using Python, Numpy and Matplotlib
To plot a masked surface plot using Python, Numpy and Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure.
- Add an 'ax' to the figure as part of a subplot arrangement.
- Return the coordinate matrices from coordinate vectors, pi and theta.
- Create x, y and z with masked data points.
- Create a surface plot with x, y, and z data points.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection="3d") pi, theta = np.meshgrid( np.arange(1, 10, 2) * np.pi / 4, np.arange(1, 10, 2) * np.pi / 4) x = np.cos(pi) * np.sin(theta) y = np.sin(pi) * np.sin(theta) z = np.ma.masked_where(x >= 0.01, y) ax.plot_surface(x, y, z, color='red') plt.show()
Output
It will produce the following output
- Related Articles
- Plotting regression and residual plot in Matplotlib
- Plotting animated quivers in Python using Matplotlib
- Plotting points on the surface of a sphere in Python's Matplotlib
- Plotting a 3D surface from a list of tuples in matplotlib?
- How to plot masked and NaN values in Matplotlib?
- Plot numpy datetime64 with Matplotlib
- How to plot scatter masked points and add a line demarking masked regions in Matplotlib?
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- Plotting multiple line graphs using Pandas and Matplotlib
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- Plotting profile histograms in Python Matplotlib
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- Plotting a cumulative graph of Python datetimes in Matplotlib
- Showing points coordinates in a plot in Python using Matplotlib

Advertisements