I really like the shaded 3d plot offered by Volume plot. Can it be used to show a “spherical wedge”? I’d like to specify radius, theta, and phi constraints (spherical coordinates). Here’s some related code:
import numpy as np
import plotly.graph_objects as go
# this code is based on an example at https://plotly.com/python/3d-volume-plots/
# it produces a partial sphere in one "octant" from rectangular coordinates
X, Y, Z = np.mgrid[:1:10j, :1:10j, :1:10j]
vol = X**2 + Y**2 + Z**2
fig = go.Figure(data=go.Volume(
x=X.flatten(), y=Y.flatten(), z=Z.flatten(),
value=vol.flatten(),
isomin=0.2,
isomax=0.7,
opacity=0.2,
))
# this is a (non-working) attempt at what I'd really like: a partial sphere specified by spherical coordinates,
# in order to show smaller or larger "wedges" than the above code
# radius, theta, phi = np.mgrid[:1:10j, np.pi*(1/8):np.pi*(3/8):10j, np.pi*(1/8):np.pi*(3/8):10j]
# X = radius * np.sin(phi) * np.cos(theta)
# Y = radius * np.sin(phi) * np.sin(theta)
# Z = radius * np.cos(phi)
# show = np.sqrt(X**2+Y**2+Z**2) >= radius.min() & \
# np.sqrt(X**2+Y**2+Z**2) <= radius.max() & \
# np.arctan2(Y,X) <= theta.max() & \
# np.arctan2(Y,X) >= theta.min() & \
# np.arccos(Z/np.sqrt(X**2+Y**2+Z**2)) <= phi.max() & \
# np.arccos(Z/np.sqrt(X**2+Y**2+Z**2)) >= phi.min()
# fig = go.Figure(data=go.Volume(
# x=X.flatten(), y=Y.flatten(), z=Z.flatten(),
# value=show.flatten(),
# isomin=.9,
# isomax=1.1,
# opacity=0.2,
# ))
fig.show()