2016-09-10 2 views
1

나는 내 선들 사이의 공간을 3D로 채우려고합니다.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() 

일부 합성 데이터 :

enter image description here

가 지금은 라인 사이의 공간을 채우려 :

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

이 생산 예 : z=-30 NOT z=0 내가 바꾸려고하는 것입니다.

df.index.values0 사이의 값을 취하고 1000입니다. 그리고 ang 데이터 프레임의 값은 -30에서 10까지입니다.

따라서,이의 오프셋 버전을 생산하기 위해 노력하고 있어요 :

enter image description here

+0

내가 당신의 데이터가 시작되고이 = 0' (적어도 Z '로 끝나는 것 같아요 'z = 0' 대신'z = -30'을 채우려면'z = -30'에 좌표를 추가/추가해야 할 것입니다. – Bart

+0

z 축의 데이터 범위는 'z = [- 30,15]'또는 그 방법에 따른 것입니다. – Astrid

+0

p.s .: 문제를 나타내는 최소한의 작업 예제 (http://stackoverflow.com/help/mcve)를 제공하면 큰 도움이됩니다. 그게 다른 사람들이 당신을 도울 수있게 해줍니다. – Bart

답변

1

코멘트에 내 제안에 대한 또 다른 해결책은 fill_between을 사용하는 것입니다; 거기에서 낮은 경계를 설정할 수 있습니다. fill_betweenPolyCollection 반환, 그래서 당신은 지금 무엇을하고 있는지 당신은 유사한 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

+0

당신은 facecolor를 바꾸는 방법을 알지 못하고이 새로운 정권을 위해 알파를 설정합니까? – Astrid

+0

채워진 다각형의 색과 알파를 의미합니까? 'fill_between()'에 인수 ('color = '', alpha = ''')를 넘겨 주어야합니다. – Bart

관련 문제