gpt4 book ai didi

python - 3D 绘图中两条线之间的着色

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:19 25 4
gpt4 key购买 nike

我正在尝试填充 3D 线条之间的空间。

我有以下代码:

from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
import matplotlib.pyplot as plt
import numpy as np

class plotting3D(object):
"""
Class to plot 3d
"""

def __init__(self):
pass

def cc(self, arg):
return colorConverter.to_rgba(arg, alpha=0.6)

def poly3d(self, df):
"""
Method to create depth of joints plot for GP regression.
"""
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')

which_joints = df.columns
dix = df.index.values
zs = [1,4]
verts = []
for j in which_joints:
verts.append(list(zip(dix,df[j])))

poly = PolyCollection(verts,facecolors=[self.cc('r'), self.cc('g')])
poly.set_alpha(0.6)
ax.add_collection3d(poly, zs=zs, zdir='y')

ax.set_ylim([0, 5])
ax.set_zlim([0, 20])
ax.set_xlim([0,dix[-1]])
ax.grid(False)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

一些综合数据:

k= pd.DataFrame(20*np.random.rand(10,2),columns=['foot','other_foot'])

产生这个:

enter image description here

现在我想填充行之间的空间并说 z=-30 而不是 z=0,这就是我想要更改的内容。

df.index.values01000 之间的值。 ang 数据帧的值范围为 -3010

因此,我正在尝试生成此版本的偏移版本:

enter image description here

最佳答案

我在评论中建议的另一个解决方案是使用 fill_ Between;您可以在那里设置下限。 fill_ Between 返回一个 PolyCollection,因此您可以将其添加到 3d 图形中,类似于您现在所做的操作:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')

# +/- your data:
z = [0,10,10,-20,10,0]
x = [0,1000,1500,2500,3000,3500]

ax.add_collection3d(plt.fill_between(x,z,0), zs=1, zdir='y') # lower boundary z=0
ax.add_collection3d(plt.fill_between(x,z,-30), zs=5, zdir='y') # lower boundary z=-30

ax.set_ylim([0, 5])
ax.set_zlim([-30, 20])
ax.set_xlim([0,3500])

enter image description here

关于python - 3D 绘图中两条线之间的着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39428656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com