In [17]:
import numpy as np
def Rnuc(theta, phi, R0 = 1., beta = 0., gamma = 0., sqrt=np.sqrt, pi=np.pi, cos=np.cos, sin=np.sin):
trig1 = cos(gamma)*(3*np.outer(cos(theta), np.ones(len(theta)))**2.-1)
trig2 = sqrt(3)*sin(gamma)*np.outer(cos(2*phi),sin(theta)**2)
R = R0*(1 + beta*sqrt(5/(16.*pi))*(trig1 + trig2))
x = R*np.outer(sin(theta), cos(phi))
y = R*np.outer(sin(theta), sin(phi))
z = R*np.outer(cos(theta), np.ones(len(theta))) # note this is 2d now
return R, x, y, z
#just a sphere
theta = np.linspace(0, np.pi/2., 15)
phi = np.linspace(0, 2*np.pi, 15)
R, x, y, z = Rnuc(theta, phi, beta=0, gamma=0.0)
In [18]:
import plotly.offline as py
import plotly.graph_objs as go
import numpy as np
py.init_notebook_mode() # run at the start of every ipython notebook to use plotly.offline
# this injects the plotly.js source files into the notebook
def mesh_line(x, y, z, Transpose = False):
if Transpose:
x = np.transpose(x)
y = np.transpose(y)
z = np.transpose(z)
return [go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker) for i, j, k in zip(x, y, z)]
mesh_square = lambda x, y, z: mesh_line(x, y, z) + mesh_line(x, y, z, Transpose=True)
# Creating the plot
lines = []
line_marker = dict(color='#0066FF', width=2)
layout = go.Layout(
title='Wireframe Plot',
width = 600,
height = 600,
scene=dict(
xaxis=dict( #yz - plane
title = 'x',
gridcolor='rgb(255, 0, 0)',
zerolinecolor='rgb(255, 255, 255)',
showbackground=True,
backgroundcolor='rgb(230, 200,200)'
),
yaxis=dict( #xz - plane
gridcolor='rgb(0, 255, 0)',
zerolinecolor='rgb(255, 255, 255)',
showbackground=True,
backgroundcolor='rgb(200, 230,200)'
),
zaxis=dict( #xy - plane
gridcolor='rgb(0, 0, 255)',
zerolinecolor='rgb(255, 255, 255)',
showbackground=True,
backgroundcolor='rgb(200, 200,230)'
)
),
showlegend=False,
)
surface = go.Data([go.Surface(x=x, y=y, z=z)])
mesh = mesh_square(x, y, z)
#mesh = mesh_line(x, y, z, Transpose=True)
#mesh = mesh_line(x, y, z, Transpose=False)
fig = go.Figure(data = mesh + surface, layout=layout)
py.iplot(fig)
In [ ]: