- 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
Plotting points on the surface of a sphere in Python's Matplotlib
To plot points on the surface of a sphere in Python, we can use plot_surface() method.
Steps
Create a new figure or activate an existing figure using figure() method.
Add a set of subplots using add_subplot() method with 3d projection.
Initialize a variable, r.
Get the theta value for spherical points and x, y, and z data points using numpy.
Plot the surface using plot_surface() method.
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(projection='3d') r = 0.05 u, v = np.mgrid[0:2 * np.pi:30j, 0:np.pi:20j] x = np.cos(u) * np.sin(v) y = np.sin(u) * np.sin(v) z = np.cos(v) ax.plot_surface(x, y, z, cmap=plt.cm.YlGnBu_r) plt.show()
Output
- Related Articles
- Plotting dates on the X-axis with Python's Matplotlib
- Plotting a masked surface plot using Python, Numpy and Matplotlib
- Plotting a 3d cube, a sphere and a vector in Matplotlib
- Plotting a 3D surface from a list of tuples in matplotlib?
- Plotting scatter points with clover symbols in Matplotlib
- Plotting a cumulative graph of Python datetimes in Matplotlib
- Putting arrowheads on vectors in Matplotlib's 3D plot
- Plotting profile histograms in Python Matplotlib
- Plotting grids across the subplots in Python Matplotlib
- Adding a line to a scatter plot using Python's Matplotlib
- Plotting animated quivers in Python using Matplotlib
- Twenty seven solid iron spheres, each of radius ( r ) and surface area ( mathrm{S} ) are melted to form a sphere with surface area ( S^{prime} ). Find the(i) radius ( r^{prime} ) of the new sphere,(ii) ratio of ( mathrm{S} ) and ( mathrm{S}^{prime} ).
- The surface area of a sphere is $3844 m^{2}$. Find the radius of the sphere.
- Making matplotlib scatter plots from dataframes in Python's pandas
- How do you get the current figure number in Python's Matplotlib?

Advertisements