Revision: 7137
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7137&view=rev
Author:   heeres
Date:     2009-05-23 14:31:14 +0000 (Sat, 23 May 2009)

Log Message:
-----------
mplot3d: contourf3d, bar / zordering

Modified Paths:
--------------
    trunk/matplotlib/examples/mplot3d/demo.py
    trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py
    trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
    trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py

Modified: trunk/matplotlib/examples/mplot3d/demo.py
===================================================================
--- trunk/matplotlib/examples/mplot3d/demo.py   2009-05-22 18:43:26 UTC (rev 
7136)
+++ trunk/matplotlib/examples/mplot3d/demo.py   2009-05-23 14:31:14 UTC (rev 
7137)
@@ -133,6 +133,6 @@
     test_plot()
     test_polys()
     test_scatter2D()
-#    test_bar2D()
+    test_bar2D()
 
     plt.show()

Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py
===================================================================
--- trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py  2009-05-22 18:43:26 UTC 
(rev 7136)
+++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py  2009-05-23 14:31:14 UTC 
(rev 7137)
@@ -91,12 +91,21 @@
         self._segments3d = segments
         LineCollection.set_segments(self, [])
 
-    def draw(self, renderer):
+    def do_3d_projection(self, renderer):
         xyslist = [
             proj3d.proj_trans_points(points, renderer.M) for points in
             self._segments3d]
         segments_2d = [zip(xs,ys) for (xs,ys,zs) in xyslist]
         LineCollection.set_segments(self, segments_2d)
+
+        minz = 1e9
+        for (xs, ys, zs) in xyslist:
+            minz = min(minz, min(zs))
+        return minz
+
+    def draw(self, renderer, project=False):
+        if project:
+            self.do_3d_projection(renderer)
         LineCollection.draw(self, renderer)
 
 def line_collection_2d_to_3d(col, z=0, dir='z'):
@@ -123,13 +132,16 @@
     def get_facecolor(self):
         return self._facecolor2d
 
-    def draw(self, renderer):
+    def do_3d_projection(self, renderer):
         s = self._segment3d
         xs, ys, zs = zip(*s)
         vxs,vys,vzs,vis = proj3d.proj_transform_clip(xs,ys,zs, renderer.M)
         self._path2d = mpath.Path(zip(vxs, vys))
         # FIXME: coloring
         self._facecolor2d = self._facecolor3d
+        return min(vzs)
+
+    def draw(self, renderer):
         Patch.draw(self, renderer)
 
 def patch_2d_to_3d(patch, z=0, dir='z'):
@@ -149,7 +161,7 @@
         self._facecolor3d = self.get_facecolor()
         self._edgecolor3d = self.get_edgecolor()
 
-    def draw(self, renderer):
+    def do_3d_projection(self, renderer):
         xs,ys,zs = self._offsets3d
         vxs,vys,vzs,vis = proj3d.proj_transform_clip(xs,ys,zs, renderer.M)
         #FIXME: mpl allows us no way to unset the collection alpha value
@@ -157,6 +169,10 @@
         self.set_facecolors(zalpha(self._facecolor3d, vzs))
         self.set_edgecolors(zalpha(self._edgecolor3d, vzs))
         PatchCollection.set_offsets(self, zip(vxs, vys))
+
+        return min(vzs)
+
+    def draw(self, renderer):
         PatchCollection.draw(self, renderer)
 
 def patch_collection_2d_to_3d(col, zs=0, dir='z'):
@@ -185,6 +201,7 @@
         ones = np.ones(len(xs))
         self._vec = np.array([xs,ys,zs,ones])
         self._segis = segis
+        self._sort_zpos = min(zs)
 
     def set_verts(self, verts, closed=True):
         self.get_vector(verts)
@@ -196,28 +213,35 @@
         self._facecolors3d = PolyCollection.get_facecolors(self)
         self._edgecolors3d = self.get_edgecolors()
 
-    def get_facecolors(self):
-        return self._facecolors2d
-    get_facecolor = get_facecolors
-
-    def draw(self, renderer):
-        txs, tys, tzs, tis = proj3d.proj_transform_vec_clip(self._vec, 
renderer.M)
-        xyslist = [(txs[si:ei], tys[si:ei], tzs[si:ei], tis[si:ei]) \
+    def do_3d_projection(self, renderer):
+        txs, tys, tzs = proj3d.proj_transform_vec(self._vec, renderer.M)
+        xyzlist = [(txs[si:ei], tys[si:ei], tzs[si:ei]) \
                 for si, ei in self._segis]
         colors = self._facecolors3d
-        #
+
         # if required sort by depth (furthest drawn first)
         if self._zsort:
-            z_segments_2d = [(min(zs),max(tis),zip(xs,ys),c) for
-                             (xs,ys,zs,tis),c in zip(xyslist,colors)]
+            z_segments_2d = [(min(zs),zip(xs,ys),c) for
+                             (xs,ys,zs),c in zip(xyzlist,colors)]
             z_segments_2d.sort()
             z_segments_2d.reverse()
         else:
             raise ValueError, "whoops"
-        segments_2d = [s for z,i,s,c in z_segments_2d if i]
-        colors = [c for z,i,s,c in z_segments_2d if i]
+        segments_2d = [s for z,s,c in z_segments_2d]
+        colors = [c for z,s,c in z_segments_2d]
         PolyCollection.set_verts(self, segments_2d)
         self._facecolors2d = colors
+
+        # Return zorder value
+        zvec = np.array([[0], [0], [self._sort_zpos], [1]])
+        ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
+        return ztrans[2][0]
+
+    def get_facecolors(self):
+        return self._facecolors2d
+    get_facecolor = get_facecolors
+
+    def draw(self, renderer):
         return Collection.draw(self, renderer)
 
 def poly_collection_2d_to_3d(col, zs=None, dir='z'):

Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
===================================================================
--- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-05-22 18:43:26 UTC 
(rev 7136)
+++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-05-23 14:31:14 UTC 
(rev 7137)
@@ -86,7 +86,7 @@
         xdw = (0.9/self.dist)
         ydwl = (0.95/self.dist)
         ydw = (0.9/self.dist)
-        #
+
         self.set_xlim(-xdwl,xdw)
         self.set_ylim(-ydwl,ydw)
 
@@ -166,6 +166,22 @@
         renderer.eye = self.eye
         renderer.get_axis_position = self.get_axis_position
 
+        # Calculate projection of collections and zorder them
+        zlist = [(col.do_3d_projection(renderer), col) \
+                for col in self.collections]
+        zlist.sort()
+        zlist.reverse()
+        for i, (z, col) in enumerate(zlist):
+            col.zorder = i
+
+        # Calculate projection of patches and zorder them
+        zlist = [(patch.do_3d_projection(renderer), patch) \
+                for patch in self.patches]
+        zlist.sort()
+        zlist.reverse()
+        for i, (z, patch) in enumerate(zlist):
+            patch.zorder = i
+
         self.w_xaxis.draw(renderer)
         self.w_yaxis.draw(renderer)
         self.w_zaxis.draw(renderer)
@@ -179,7 +195,7 @@
         zhigh = tc[0][2]>tc[2][2]
         return xhigh,yhigh,zhigh
 
-    def update_datalim(self, xys):
+    def update_datalim(self, xys, **kwargs):
         pass
 
     def update_datalim_numerix(self, x, y):
@@ -293,12 +309,12 @@
 
         # look into the middle of the new coordinates
         R = np.array([0.5,0.5,0.5])
-        #
+
         xp = R[0] + np.cos(razim)*np.cos(relev)*self.dist
         yp = R[1] + np.sin(razim)*np.cos(relev)*self.dist
         zp = R[2] + np.sin(relev)*self.dist
         E = np.array((xp, yp, zp))
-        #
+
         self.eye = E
         self.vvec = R - E
         self.vvec = self.vvec / proj3d.mod(self.vvec)
@@ -393,7 +409,7 @@
         ldists.sort()
         # nearest edge
         edgei = ldists[0][1]
-        #
+
         p0,p1 = edges[edgei]
 
         # scale the z value to match
@@ -403,7 +419,6 @@
         d1 = np.hypot(x1-xd,y1-yd)
         dt = d0+d1
         z = d1/dt * z0 + d0/dt * z1
-        #print 'mid', edgei, d0, d1, z0, z1, z
 
         x,y,z = proj3d.inv_transform(xd,yd,z,self.M)
 
@@ -440,8 +455,8 @@
         if self.button_pressed == 1:
             # rotate viewing point
             # get the x and y pixel coords
-            if dx == 0 and dy == 0: return
-            #
+            if dx == 0 and dy == 0:
+                return
             self.elev = axis3d.norm_angle(self.elev - (dy/h)*180)
             self.azim = axis3d.norm_angle(self.azim - (dx/w)*180)
             self.get_proj()
@@ -450,7 +465,6 @@
             # pan view
             # project xv,yv,zv -> xw,yw,zw
             # pan
-            #
             pass
         elif self.button_pressed == 3:
             # zoom view
@@ -469,7 +483,7 @@
     def set_xlabel(self, xlabel, fontdict=None, **kwargs):
         #par = cbook.popd(kwargs, 'par',None)
         #label.set_par(par)
-        #
+
         label = self.w_xaxis.get_label()
         label.set_text(xlabel)
         if fontdict is not None: label.update(fontdict)
@@ -524,7 +538,7 @@
         tX,tY,tZ = np.transpose(X), np.transpose(Y), np.transpose(Z)
         rstride = kwargs.pop('rstride', 10)
         cstride = kwargs.pop('cstride', 10)
-        #
+
         polys = []
         boxes = []
         for rs in np.arange(0,rows-1,rstride):
@@ -543,7 +557,7 @@
                     ps.append(z)
                 boxes.append(map(np.array,zip(*corners)))
                 polys.append(zip(*ps))
-        #
+
         lines = []
         shade = []
         for box in boxes:
@@ -552,7 +566,7 @@
             n = n/proj3d.mod(n)*5
             shade.append(np.dot(n,[-1,-1,0.5]))
             lines.append((box[0],n+box[0]))
-        #
+
         color = np.array([0,0,1,1])
         norm = Normalize(min(shade),max(shade))
         colors = [color * (0.5+norm(v)*0.5) for v in shade]
@@ -560,7 +574,7 @@
         polyc = art3d.Poly3DCollection(polys, facecolors=colors, *args, 
**kwargs)
         polyc._zsort = 1
         self.add_collection(polyc)
-        #
+
         self.auto_scale_xyz(X,Y,Z, had_data)
         return polyc
 
@@ -578,11 +592,11 @@
         xlines = [X[i] for i in rii]
         ylines = [Y[i] for i in rii]
         zlines = [Z[i] for i in rii]
-        #
+
         txlines = [tX[i] for i in cii]
         tylines = [tY[i] for i in cii]
         tzlines = [tZ[i] for i in cii]
-        #
+
         lines = [zip(xl,yl,zl) for xl,yl,zl in zip(xlines,ylines,zlines)]
         lines += [zip(xl,yl,zl) for xl,yl,zl in zip(txlines,tylines,tzlines)]
         linec = self.add_lines(lines, *args, **kwargs)
@@ -614,6 +628,7 @@
             zs = [z1] * (len(linec.get_paths()[0])/2)
             zs += [z2] * (len(linec.get_paths()[0])/2)
             art3d.poly_collection_2d_to_3d(linec, zs)
+
         self.auto_scale_xyz(X,Y,Z, had_data)
         return cset
     
@@ -701,6 +716,7 @@
 
     def bar(self, left, height, z=0, dir='z', *args, **kwargs):
         had_data = self.has_data()
+
         patches = self.wrapped.bar(left, height, *args, **kwargs)
         verts = []
         for p in patches:
@@ -863,6 +879,6 @@
     test_plot()
     test_polys()
     test_scatter2D()
-#    test_bar2D()
+    test_bar2D()
     
     pylab.show()

Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py
===================================================================
--- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py 2009-05-22 18:43:26 UTC 
(rev 7136)
+++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py 2009-05-23 14:31:14 UTC 
(rev 7137)
@@ -85,7 +85,7 @@
         # data and viewing intervals for this direction
         self.d_interval = d_intervalx
         self.v_interval = v_intervalx
-        #
+
         axis.XAxis.__init__(self, axes, *args, **kwargs)
         self.line = lines.Line2D(xdata=(0,0),ydata=(0,0),
                                  linewidth=0.75,
@@ -248,7 +248,7 @@
         lines = zip(xyz1, xyz0, xyz2)
         self.gridlines.set_segments(lines)
         self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines))
-        self.gridlines.draw(renderer)
+        self.gridlines.draw(renderer, project=True)
 
         # Draw ticks
         tickdir = info['tickdir']


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to