简体   繁体   English

使用非规则角度绘制3D球形参数化曲面

[英]plot 3D spherical parametric surface using non-regular angles

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) . 该文件根据球面角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. 我经历了matlibplot和Mayavi,在所有情况下都需要提供我没有的2D阵列。

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 ar = f(theta,phi)). 我不知道我是否完全理解您的问题,但无论如何我还是尝试提供了一个平滑的,部分随机的曲面和一个完全随机的曲面(ar = f(theta,phi))的可能绘图(使用plot_surface AND plotly)。

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): 以下是两个“ way”的std输出(按照代码中显示的顺序): 在此处输入图片说明 在此处输入图片说明

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')

在此处输入图片说明 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM