【发布时间】:2016-11-08 02:49:52
【问题描述】:
我希望制作一个类似于found here 的图,只是我想设置每个点到中心的距离。即,给定绘图的一部分是一个圆圈,我希望每个点都与中心有可定义的距离。
如果对前面提到的答案进行简单修改,我首先要了解:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from scipy.interpolate import interp1d
from matplotlib import cm
from matplotlib import pyplot as plt
step = 0.04
maxval = 1.0
fig = plt.figure()
ax = Axes3D(fig)
# u here would define the desired distance from radial axis
# u=np.array([0,1,2,1,0,2,4,6,4,2,1])
v=np.array([4,4,6,3,6,4,1,4,4,4,4])
r=np.array([0,1,2,3,4,5,6,7,8,9,10])
f=interp1d(r,u)
# walk along the circle
p = np.linspace(0,2*np.pi,len(r))
R,P = np.meshgrid(r,p)
# transform them to cartesian system
X,Y = R*np.cos(P),R*np.sin(P)
Z=f(R)
ax.scatter(X, Y, Z)#, rstride=1, cstride=1, cmap=cm.jet)
ax.set_xticks([])
fig.savefig(str(output_prefix + '3d..png'), dpi=(200))
我尝试使用 interp2d 添加上面注释掉的 u 变量,但没有运气。将Z 更改为数组u 会引发错误,即X、Y 和Z 的大小必须相同("Argument 'zs' must be of same size as 'xs' ",可以理解为 X 和 Y 现在已内插)我需要做什么?任何提示将不胜感激!
【问题讨论】:
标签: python matplotlib plot 3d