2016-08-02 26 views
0

1つの3Dプロットに2セットのデータをプロットしようとしています。私が見ることを期待何 は同じプロット上のこれら二つの画像です: enter image description herePython matplot3d - 同じ3Dプロット上に2つのデータセットをプロットする

私が探していますプロットはこれです:enter image description here

私はアナコンダや木星、matplotlibの1.5.1を使用します。

これは、これまでの私のコードです:

from mpl_toolkits.mplot3d import Axes3D 
import mpl_toolkits.mplot3d as a3 
import matplotlib.pyplot as plt 
import cop 

class var1: 
    def __init__(self,b1, b2): 
     self.pt1 = copy.deepcopy(b1)  
     self.pt2 = copy.deepcopy(b2) 
     self.cords = (
      list(self.pt1 + [high]), # top-left 
      list(self.pt2 + [high]), # top-right 
      list(self.pt2 + [low]), # bottom-right 
      list(self.pt1 + [low]), # bottom-left 
      )    
    def drawFunction(self):  
     dataSet1 = a3.art3d.Poly3DCollection([self.cords]) 
     dataSet1.set_color('firebrick') 
     dataSet1.set_edgecolor('k') 
     ax.add_collection3d(dataSet1) #If you comment out this line- var2 will be shown. I`m trying to show one on top of the other 
     var2(self.pt1, self.pt2, high, low).drawFunction() 

class var2: 
    def __init__(self,b1, b2, high, low): 
     self.pt1 = copy.deepcopy(b1)  
     self.pt2 = copy.deepcopy(b2) 
     self.cords = (
      list(self.pt1 + [(high/2) + (high/4)]), # top-left 
      list(self.pt2 + [(high/2) + (high/4)]), # top-right 
      list(self.pt2 + [(high/2) - (high/4)]), # bottom-right 
      list(self.pt1 + [(high/2) - (high/4)]), # bottom-left 
      )  
    def drawFunction(self): 
     dataSet2 = a3.art3d.Poly3DCollection([self.cords]) 
     dataSet2.set_color('cornflowerblue') 
     dataSet2.set_edgecolor('k') 
     ax.add_collection3d(dataSet2) 

high = 500 
low = 0 
fig = plt.figure() 
ax = Axes3D(fig) 

i = 0 
while i<4: 
    if (i==0): 
     p1 = [0,200] 
     p2 = [0,0] 
    if (i==1): 
     p1 = [0,0] 
     p2 = [200,0] 
    if (i==2): 
     p1 = [200,0] 
     p2 = [200,200] 
    if (i==3): 
     p1 = [200,200] 
     p2 = [0,200] 

    var1(p1, p2).drawFunction() 
    i = i+1 

ax.set_xlim(0,200) 
ax.set_ylim(0, 200) 
ax.set_zlim(0, 1000) 
plt.show() 
+0

編集部分をご覧ください。 – Yair

+0

コードが更新されました – Yair

答えて

0

注意、それは数字の両方が存在しているサンプルコードでは、あなたは次のようPoly3DCollection([self.cords],alpha=0.5)にコードを変更することでそれを見ることができます。 add_collection3dが一方を他方の上に描画しているだけなので、両方を見ることはできません。

私はそれを打ち負かす方法を見つけませんでしたが、回避策としてhereを見ることができます。

ところで、コードにはimport copyax = a3.Axes3D(fig)が機能しません。

関連する問題