Skip to content

Instantly share code, notes, and snippets.

@UlisseMini
Created September 5, 2021 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UlisseMini/a64acaf95f84c98d38a7b70c589d5a9f to your computer and use it in GitHub Desktop.
Save UlisseMini/a64acaf95f84c98d38a7b70c589d5a9f to your computer and use it in GitHub Desktop.
Plot bumpy sphere
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