Created
September 5, 2021 01:23
-
-
Save UlisseMini/a64acaf95f84c98d38a7b70c589d5a9f to your computer and use it in GitHub Desktop.
Plot bumpy sphere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.graph_objects as go | |
import plotly.express as px | |
import numpy as np | |
import pandas as pd | |
# constants | |
m, n = 6, 5 | |
pi = np.pi | |
def vec_x(theta, phi): | |
p = 1 + 0.2 * np.sin(m*theta)*np.sin(n*phi) | |
# convert from spherical to cartesian | |
return p * np.array([ | |
np.sin(phi) * np.cos(theta), | |
np.sin(phi) * np.sin(theta), | |
np.cos(phi) | |
]) | |
u, v = np.mgrid[0:2*pi:100j, 0:2*pi:100j] | |
x,y,z = vec_x(u, v) | |
# each x,y,z has shape (N,N) since it has a value for each (u,v) | |
# plot surface | |
fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)]) | |
fig.update_layout(title='Bumpy sphere', autosize=True) | |
fig.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment