我有一个数据文件是数值计算的结果。该文件采样一定量作为球面角度 r(th,ph)的函数。
th ph r
0.012 1.456 24
0.014 1.25 23.5
......
球面角度跨越球体的整个参数曲面,但不要形成任何明显的网格。为简单起见,假设球面角度是随机的。
我想绘制一个拟合这些数据的曲面。请注意,我绘制的曲面不是凸面。
我已经通过了matlibplot和Mayavi,在所有情况下我都需要提供一个我不具备的2D阵列。
答案 0 :(得分:0)
我不知道我是否完全理解你的问题,但无论如何我都试图提供一个平滑的,部分随机的表面和一个完全随机的表面(使用plot_surface和plotly)(ar = 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()
情节版(相同的表示顺序):
# 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')