From: <he...@us...> - 2009-05-28 15:59:18
|
Revision: 7154 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7154&view=rev Author: heeres Date: 2009-05-28 15:59:12 +0000 (Thu, 28 May 2009) Log Message: ----------- mplot3d: add examples, fix NaN bug Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/__init__.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Added Paths: ----------- trunk/matplotlib/examples/mplot3d/contour.py trunk/matplotlib/examples/mplot3d/contourf.py trunk/matplotlib/examples/mplot3d/polys.py trunk/matplotlib/examples/mplot3d/scatter.py trunk/matplotlib/examples/mplot3d/surface.py trunk/matplotlib/examples/mplot3d/wire.py Added: trunk/matplotlib/examples/mplot3d/contour.py =================================================================== --- trunk/matplotlib/examples/mplot3d/contour.py (rev 0) +++ trunk/matplotlib/examples/mplot3d/contour.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1,12 @@ +from mpl_toolkits.mplot3d import axes3d +import pylab +import random + +fig = pylab.figure() +ax = axes3d.Axes3D(fig) +X, Y, Z = axes3d.get_test_data(0.05) +cset = ax.contour3D(X, Y, Z) +ax.clabel(cset, fontsize=9, inline=1) + +pylab.show() + Added: trunk/matplotlib/examples/mplot3d/contourf.py =================================================================== --- trunk/matplotlib/examples/mplot3d/contourf.py (rev 0) +++ trunk/matplotlib/examples/mplot3d/contourf.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1,12 @@ +from mpl_toolkits.mplot3d import axes3d +import pylab +import random + +fig = pylab.figure() +ax = axes3d.Axes3D(fig) +X, Y, Z = axes3d.get_test_data(0.05) +cset = ax.contourf3D(X, Y, Z) +ax.clabel(cset, fontsize=9, inline=1) + +pylab.show() + Added: trunk/matplotlib/examples/mplot3d/polys.py =================================================================== --- trunk/matplotlib/examples/mplot3d/polys.py (rev 0) +++ trunk/matplotlib/examples/mplot3d/polys.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1,31 @@ +from mpl_toolkits.mplot3d import Axes3D +from matplotlib.collections import PolyCollection +from matplotlib.colors import colorConverter +import pylab +import random +import numpy as np + +fig = pylab.figure() +ax = Axes3D(fig) + +cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6) + +xs = np.arange(0, 10, 0.4) +verts = [] +zs = [0.0, 1.0, 2.0, 3.0] +for z in zs: + ys = [random.random() for x in xs] + ys[0], ys[-1] = 0, 0 + verts.append(zip(xs, ys)) + +poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'), + cc('y')]) +poly.set_alpha(0.7) +ax.add_collection(poly, zs=zs, dir='y') + +ax.set_xlim(0, 10) +ax.set_ylim(-1, 4) +ax.set_zlim(0, 1) + +pylab.show() + Added: trunk/matplotlib/examples/mplot3d/scatter.py =================================================================== --- trunk/matplotlib/examples/mplot3d/scatter.py (rev 0) +++ trunk/matplotlib/examples/mplot3d/scatter.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1,21 @@ +from mpl_toolkits.mplot3d import Axes3D +import pylab +import random + +fig = pylab.figure() +ax = Axes3D(fig) +n = 100 +for c, zl, zh in [('r', -50, -25), ('b', -30, -5)]: + xs, ys, zs = zip(* + [(random.randrange(23, 32), + random.randrange(100), + random.randrange(zl, zh) + ) for i in range(n)]) + ax.scatter3D(xs, ys, zs, c=c) + +ax.set_xlabel('X Label') +ax.set_ylabel('Y Label') +ax.set_zlabel('Z Label') + +pylab.show() + Added: trunk/matplotlib/examples/mplot3d/surface.py =================================================================== --- trunk/matplotlib/examples/mplot3d/surface.py (rev 0) +++ trunk/matplotlib/examples/mplot3d/surface.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1,16 @@ +from mpl_toolkits.mplot3d import Axes3D +import pylab +import random +import numpy as np + +fig = pylab.figure() +ax = Axes3D(fig) +X = np.arange(-5, 5, 0.5) +Y = np.arange(-5, 5, 0.5) +X, Y = np.meshgrid(X, Y) +R = np.sqrt(X**2 + Y**2) +Z = np.sin(R) +ax.plot_surface(X, Y, Z, rstride=1, cstride=1, color='forestgreen') + +pylab.show() + Added: trunk/matplotlib/examples/mplot3d/wire.py =================================================================== --- trunk/matplotlib/examples/mplot3d/wire.py (rev 0) +++ trunk/matplotlib/examples/mplot3d/wire.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1,12 @@ +from mpl_toolkits.mplot3d import axes3d +import pylab +import random +import numpy as np + +fig = pylab.figure() +ax = axes3d.Axes3D(fig) +X, Y, Z = axes3d.get_test_data(0.05) +ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) + +pylab.show() + Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/__init__.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/__init__.py 2009-05-28 14:49:14 UTC (rev 7153) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/__init__.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -0,0 +1 @@ +from axes3d import Axes3D Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-05-28 14:49:14 UTC (rev 7153) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-05-28 15:59:12 UTC (rev 7154) @@ -539,6 +539,9 @@ rstride = kwargs.pop('rstride', 10) cstride = kwargs.pop('cstride', 10) + color = kwargs.pop('color', 'b') + color = np.array(colorConverter.to_rgba(color)) + polys = [] boxes = [] for rs in np.arange(0,rows-1,rstride): @@ -567,8 +570,10 @@ 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)) + shade = np.array(shade) + mask = ~np.isnan(shade) + norm = Normalize(min(shade[mask]), max(shade[mask])) + colors = [color * (0.5+norm(v)*0.5) for v in shade] for c in colors: c[3] = 1 polyc = art3d.Poly3DCollection(polys, facecolors=colors, *args, **kwargs) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |