plot 3D spherical parametric surface using non-regular angles

1.3k Views Asked by At

I have a data file which is a result of numerical computation. This file samples a certain quantity as a function of spherical angles r(th, ph).

th ph r
0.012 1.456 24
0.014 1.25 23.5
......

The spherical angles span the entire parametric surface of a sphere, but DO NOT form any obvious mesh. For simplicity, assume that the spherical angles are random.

I would like to plot a surface fitting these data. Note that the surface I am plotting is not convex.

I have gone through matlibplot and Mayavi, and in all cases I am required to provide a 2D array that I don't have.

1

There are 1 best solutions below

0
Garini On

I do not know if I fully understood your question but I tried anyway to provide the possible plotting (using plot_surface AND plotly) of a smoothed, partially random surface and a fully random one (with a r = f(theta,phi)).

import scipy.signal as scsi
import numpy
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# FIRST WAY: make just a strange  sphere (it works even if not continuous) - it seems a nice vase
theta = linspace(0,2*pi,100) 
phi = linspace(0,pi,100) + scsi.savgol_filter(numpy.random.normal(1.5,0.5, 100),11,2)
r = scsi.savgol_filter(numpy.random.normal(2,0.2,theta.shape[0]),11,3)
# N.B. you can use the savgol_filter to 'fit' a presupposed random noise

# SECOND WAY: this is instead flat random
theta = numpy.random.uniform(0,pi, 100)
phi = numpy.random.uniform(0, pi, 100)
# this would be your r = f(theta, phi)
r = theta*2 + phi # random function

x = r*outer(cos(theta),sin(phi))
y = r*outer(sin(theta),sin(phi))
z = r*outer(ones(100),cos(phi))

# plotting (std)
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.plot_surface(x,y,z, alpha=0.1)
plt.draw()
plt.show()

The following are the std output for the two 'ways' (in the order presented in the code): enter image description hereenter image description here

plotly version (same order of representation):

# PLOTLY VERSION - DYNAMIC PLOTTING
import plotly
import plotly.plotly as py
from plotly.graph_objs import *

data = Data([ Surface(x=x, y=y, z=z) ])
fig = Figure(data=data)
py.iplot(fig, filename='bloch-sphere-surface')

enter image description hereenter image description here