【问题标题】:Matplotlib: Plot 2d array radially to make 3d ScatterplotMatplotlib:径向绘制 2d 数组以制作 3d 散点图
【发布时间】: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


    【解决方案1】:

    我不知道你的问题到底是什么意思。 我将v 设为圆心在x 轴上的偏移量。

    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    from scipy.interpolate import interp1d
    from matplotlib import pyplot as plt
    step = 0.04
    maxval = 1.0
    fig = plt.figure()
    ax = Axes3D(fig)
    # v 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
    V = np.tile(v, (len(u), 1))
    p = np.linspace(0,2*np.pi,len(r))
    R,P = np.meshgrid(r,p)
    # transform them to cartesian system
    X,Y = V + 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([])
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2021-04-07
      • 1970-01-01
      • 2022-01-02
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 2014-09-03
      相关资源
      最近更新 更多