0

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.

Aleksejs Fomins
  • 688
  • 1
  • 8
  • 20
  • What have you tried so far in Python? Which modules are you using? Can you give an example of the input data? – tommy.carstensen Oct 12 '16 at 13:31
  • so far I have tried python's plot_surface() and Mayavi's mesh(), but both only work with regular grids – Aleksejs Fomins Oct 12 '16 at 13:38
  • 1
    Would it be an option for you to do a 2D polar plot? http://matplotlib.org/examples/pylab_examples/polar_demo.html Have you checked this example? http://stackoverflow.com/questions/25236026/circular-interpolated-heat-map-plot-using-python – tommy.carstensen Oct 12 '16 at 13:41
  • Nope, I want it in 3D :) The example is useful. I can, of course, map data on a rectangle, then interpolate, and then map back onto a sphere, so I am not completely at a loss. But I was hoping that this problem is common enough for the solution to already exist – Aleksejs Fomins Oct 12 '16 at 13:45
  • OK, I think this is what you want then: http://stackoverflow.com/questions/36816537/spherical-coordinates-plot-in-matplotlib – tommy.carstensen Oct 12 '16 at 14:00
  • Oh, come on man, I explicitly wrote that plot_surface does not work with irregular data. In the example you share they use range function to regularly sample over the spherical angle – Aleksejs Fomins Oct 12 '16 at 14:04

1 Answers1

0

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

Garini
  • 1,088
  • 16
  • 29