0

I`m trying to plot 2 sets of data on a single 3D plot. What I expect to see is these two images on the same plot: enter image description here

The plot I am looking for is this: enter image description here

I use Anaconda and Jupiter, matplotlib 1.5.1.

This is my code so far:

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()
Yair
  • 859
  • 2
  • 12
  • 27

1 Answers1

0

Note, that in the example code both the figures are present, you can see it by changing the code in the following way Poly3DCollection([self.cords],alpha=0.5). It's just that the add_collection3d draws one over the other, so you don't see both.

I didn't find a way to beat it, but you can look here for a possible workaround.

BTW, the code is missing import copy and ax = a3.Axes3D(fig) to work.

Aruj
  • 82
  • 1
  • 10