Revision: 8915
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8915&view=rev
Author:   weathergod
Date:     2011-01-13 19:07:12 +0000 (Thu, 13 Jan 2011)

Log Message:
-----------
contourf3d can now project the filled contour onto a particular plane
much like how contour3d can do with contour lines using zdir and offset
arguments.

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py

Added Paths:
-----------
    trunk/matplotlib/examples/mplot3d/contourf3d_demo2.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2011-01-13 13:58:37 UTC (rev 8914)
+++ trunk/matplotlib/CHANGELOG  2011-01-13 19:07:12 UTC (rev 8915)
@@ -1,3 +1,6 @@
+2011-01-13 Added zdir and offset arguments to contourf3d to
+           bring contourf3d in feature parity with contour3d. - BVR
+
 2011-01-04 Tag 1.0.1 for release at r8896
 
 2011-01-03 Added display of ticker offset to 3d plots. - BVR

Added: trunk/matplotlib/examples/mplot3d/contourf3d_demo2.py
===================================================================
--- trunk/matplotlib/examples/mplot3d/contourf3d_demo2.py                       
        (rev 0)
+++ trunk/matplotlib/examples/mplot3d/contourf3d_demo2.py       2011-01-13 
19:07:12 UTC (rev 8915)
@@ -0,0 +1,20 @@
+from mpl_toolkits.mplot3d import axes3d
+import matplotlib.pyplot as plt
+
+fig = plt.figure()
+ax = fig.gca(projection='3d')
+X, Y, Z = axes3d.get_test_data(0.05)
+ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
+cset = ax.contourf(X, Y, Z, zdir='z', offset=-100)
+cset = ax.contourf(X, Y, Z, zdir='x', offset=-40)
+cset = ax.contourf(X, Y, Z, zdir='y', offset=40)
+
+ax.set_xlabel('X')
+ax.set_xlim3d(-40, 40)
+ax.set_ylabel('Y')
+ax.set_ylim3d(-40, 40)
+ax.set_zlabel('Z')
+ax.set_zlim3d(-100, 100)
+
+plt.show()
+

Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
===================================================================
--- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2011-01-13 13:58:37 UTC 
(rev 8914)
+++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2011-01-13 19:07:12 UTC 
(rev 8915)
@@ -941,6 +941,14 @@
                     z = offset
                 art3d.line_collection_2d_to_3d(linec, z, zdir=zdir)
 
+    def add_contourf_set(self, cset, zdir='z', offset=None) :
+        zdir = '-' + zdir
+        for z, linec in zip(cset.levels, cset.collections) :
+            if offset is not None :
+                z = offset
+            art3d.poly_collection_2d_to_3d(linec, z, zdir=zdir)
+            linec.set_sort_zpos(z)
+
     def contour(self, X, Y, Z, *args, **kwargs):
         '''
         Create a 3D contour plot.
@@ -1017,9 +1025,17 @@
 
     def contourf(self, X, Y, Z, *args, **kwargs):
         '''
-        Plot filled 3D contours.
+        Create a 3D contourf plot.
 
-        *X*, *Y*, *Z*: data points.
+        ==========  ================================================
+        Argument    Description
+        ==========  ================================================
+        *X*, *Y*,   Data values as numpy.arrays
+        *Z*
+        *zdir*      The direction to use: x, y or z (default)
+        *offset*    If specified plot a projection of the filled contour
+                    on this position in plane normal to zdir
+        ==========  ================================================
 
         The positional and keyword arguments are passed on to
         :func:`~matplotlib.axes.Axes.contourf`
@@ -1027,14 +1043,14 @@
         Returns a :class:`~matplotlib.axes.Axes.contourf`
         '''
 
+        zdir = kwargs.pop('zdir', 'z')
+        offset = kwargs.pop('offset', None)
+
         had_data = self.has_data()
 
-        cset = Axes.contourf(self, X, Y, Z, *args, **kwargs)
-        levels = cset.levels
-        colls = cset.collections
-        for z1, z2, linec in zip(levels, levels[1:], colls):
-            art3d.poly_collection_2d_to_3d(linec, z1)
-            linec.set_sort_zpos(z1)
+        jX, jY, jZ = art3d.rotate_axes(X, Y, Z, zdir)
+        cset = Axes.contourf(self, jX, jY, jZ, *args, **kwargs)
+        self.add_contourf_set(cset, zdir, offset)
 
         self.auto_scale_xyz(X, Y, Z, had_data)
         return cset
@@ -1063,17 +1079,10 @@
         Returns a :class:`~matplotlib.axes.Axes.contour`
         '''
 
-        zdir = '-' + zdir
         had_data = self.has_data()
 
         cset = Axes.tricontourf(self, X, Y, Z, *args, **kwargs)
-        levels = cset.levels
-        colls = cset.collections
-        for z1, linec in zip(levels, colls):
-            if offset is not None:
-                z1 = offset
-            art3d.poly_collection_2d_to_3d(linec, z1, zdir=zdir)
-            linec.set_sort_zpos(z1)
+        self.add_contourf_set(cset, zdir, offset)
 
         self.auto_scale_xyz(X, Y, Z, had_data)
         return cset


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

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to