Hi @seismojoe,
You can define a sphere as the parameteric surface, using your parameterization (given in the code posted here),
but with a constant radius, and theta, phi, given in radians, not degrees, because in Python, as in math,
the functions sin and cos are evaluated at radian arguments. The sphere can be colored according to the values of a function, C(x,y,z) (or pdf in your case), evaluaed at the surface points.
import numpy as np
from numpy import sin, cos, pi
import plotly.graph_objects as go
theta = np.linspace(0, pi, 50)
phi= np.linspace(-pi, pi, 100)
theta, phi = np.meshgrid(theta, phi)
r= 1
X = r * sin(theta) * cos(phi)
Y = r * sin(theta) * sin(phi)
Z = r * cos(theta)
coloringF= Z**2*Y+cos(X**3+Z) # this the function C(X, Y, Z)
fig1= go.Figure(go.Surface(x=X, y=Y, z=Z,
surfacecolor=coloringF,
colorbar_thickness=23,
colorbar_len=0.7))
fig1.update_layout(width=700, height=700)
If you want to define it as an isosurface, carved within a volume, then you define a meshgrid over a cube of side slightly
greater that the sphere diameter. Within this volume is carved a sphere of equation x^2+y^2+z^2= R^2.
To carve it, plotly.js evaluates the function F(x,y,z) =x^2+y^2+z^2-R^2 at the points of the meshgrid, and by an algorithm
working behind the scene, it finds the isosurface F(x,y,z)=(isomin+isomax)/2. An isosurface is colored uniformly, namely with the color at the mid of the colorscale.
In this case you can define a constant colorscale:
x, y, z = np.mgrid[-1.5:1.5:30j, -1.5:1.5:30j, -1.5:1.5:30j ] #meshgrid over the cube with center at the origin
value = x**2+y**2+z**2-1 #F(x,y, z)=x**2+y**2+z**2-1
fig = go.Figure()
fig.add_trace(go.Isosurface(
x=x.flatten(),
y=y.flatten(),
z=z.flatten(),
value=value.flatten(),
surface=dict(show=True, count=1, fill=0.9),
colorscale=[[0, 'rgb(0, 215, 0)'], [1, 'rgb(0, 215, 0)']],
showscale=False,
isomin= -1, isomax = 1 # these settings ensure that plotly.js will carve the sphere of eq F(x,y, z)=(-1+1)/2=0
))
fig.update_layout(width=700, height=700)
fig.show()
If you are interested to plot a distribution over the sphere (a deduced that from your value=pdf), then you
cannot do it on an isosurface.