From: <jd...@us...> - 2009-08-08 11:25:40
|
Revision: 7427 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7427&view=rev Author: jdh2358 Date: 2009-08-08 11:25:32 +0000 (Sat, 08 Aug 2009) Log Message: ----------- Merged revisions 7426 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_99_maint ........ r7426 | jdh2358 | 2009-08-08 06:00:41 -0500 (Sat, 08 Aug 2009) | 1 line replace list comps w/ numpy in mplot3d ........ Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7424 + /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7426 Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py 2009-08-08 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py 2009-08-08 11:25:32 UTC (rev 7427) @@ -92,6 +92,7 @@ def set_3d_properties(self, zs=0, zdir='z'): xs = self.get_xdata() ys = self.get_ydata() + try: zs = float(zs) zs = [zs for x in xs] @@ -116,7 +117,7 @@ '''Convert a path to a 3D segment.''' if not iterable(zs): - zs = [zs] * len(path) + zs = np.ones(len(path)) * zs seg = [] pathsegs = path.iter_segments(simplify=False, curves=False) @@ -131,7 +132,7 @@ ''' if not iterable(zs): - zs = [zs] * len(paths) + zs = np.ones(len(paths)) * zs segments = [] for path, pathz in zip(paths, zs): @@ -192,7 +193,8 @@ def set_3d_properties(self, verts, zs=0, zdir='z'): if not iterable(zs): - zs = [zs] * len(verts) + zs = np.ones(len(verts)) * zs + self._segment3d = [juggle_axes(x, y, z, zdir) \ for ((x, y), z) in zip(verts, zs)] self._facecolor3d = Patch.get_facecolor(self) Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-08-08 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-08-08 11:25:32 UTC (rev 7427) @@ -58,7 +58,7 @@ xticks=[], yticks=[], *args, **kwargs) self.M = None - + self._ready = 1 self.mouse_init() self.create_axes() @@ -184,7 +184,7 @@ def autoscale_view(self, scalex=True, scaley=True, scalez=True): # This method looks at the rectanglular volume (see above) # of data and decides how to scale the view portal to fit it. - + self.set_top_view() if not self._ready: return @@ -534,7 +534,7 @@ # Match length if not cbook.iterable(zs): - zs = [zs] * len(xs) + zs = np.ones(len(xs)) * zs lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs) for line in lines: @@ -552,7 +552,7 @@ By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the *cmap* argument. - + ========== ================================================ Argument Description ========== ================================================ @@ -648,7 +648,7 @@ shade = np.array(shade) mask = ~np.isnan(shade) - if len(shade[mask]) > 0: + if len(shade[mask]) > 0: norm = Normalize(min(shade[mask]), max(shade[mask])) color = color.copy() color[3] = 1 @@ -679,7 +679,7 @@ rstride = kwargs.pop("rstride", 1) cstride = kwargs.pop("cstride", 1) - + had_data = self.has_data() rows, cols = Z.shape @@ -708,7 +708,7 @@ def _3d_extend_contour(self, cset, stride=5): ''' - Extend a contour in 3D by creating + Extend a contour in 3D by creating ''' levels = cset.levels @@ -742,7 +742,7 @@ v1 = np.array(topverts[0][i1]) - np.array(topverts[0][i2]) v2 = np.array(topverts[0][i1]) - np.array(botverts[0][i1]) normals.append(np.cross(v1, v2)) - + colors = self._shade_colors(color, normals) colors2 = self._shade_colors(color, normals) polycol = art3d.Poly3DCollection(polyverts, facecolors=colors, @@ -811,13 +811,13 @@ self.auto_scale_xyz(X, Y, Z, had_data) return cset - + contourf3D = contourf def add_collection3d(self, col, zs=0, zdir='z'): ''' Add a 3d collection object to the plot. - + 2D collection types are converted to a 3D version by modifying the object and adding z coordinate information. @@ -865,7 +865,7 @@ patches = Axes.scatter(self, xs, ys, *args, **kwargs) if not cbook.iterable(zs): is_2d = True - zs = [zs] * len(xs) + zs = np.ones(len(xs)) * zs else: is_2d = False art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir) @@ -903,8 +903,9 @@ patches = Axes.bar(self, left, height, *args, **kwargs) if not cbook.iterable(zs): - zs = [zs] * len(left) + zs = np.ones(len(left))*zs + verts = [] verts_zs = [] for p, z in zip(patches, zs): Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py 2009-08-08 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py 2009-08-08 11:25:32 UTC (rev 7427) @@ -22,6 +22,7 @@ def move_from_center(coord, centers, deltas, axmask=(True, True, True)): '''Return a coordinate that is moved by "deltas" away from the center.''' coord = copy.copy(coord) + #print coord, centers, deltas, axmask for i in range(3): if not axmask[i]: continue @@ -84,7 +85,7 @@ alpha=0.8, facecolor=(1,1,1,0), edgecolor=(1,1,1,0)) - + self.axes._set_artist_props(self.line) self.axes._set_artist_props(self.pane) self.gridlines = art3d.Line3DCollection([], ) @@ -141,7 +142,7 @@ # code from XAxis majorTicks = self.get_major_ticks() majorLocs = self.major.locator() - + # filter locations here so that no extra grid lines are drawn interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ @@ -152,19 +153,20 @@ # Determine bounds minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims() - mins = (minx, miny, minz) - maxs = (maxx, maxy, maxz) - centers = [(maxv + minv) / 2 for minv, maxv in zip(mins, maxs)] - deltas = [(maxv - minv) / 12 for minv, maxv in zip(mins, maxs)] - mins = [minv - delta / 4 for minv, delta in zip(mins, deltas)] - maxs = [maxv + delta / 4 for maxv, delta in zip(maxs, deltas)] + mins = np.array((minx, miny, minz)) + maxs = np.array((maxx, maxy, maxz)) + centers = (maxs + mins) / 2. + deltas = (maxs - mins) / 12. + mins = mins - deltas / 4. + maxs = maxs + deltas / 4. # Determine which planes should be visible by the avg z value vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2] tc = self.axes.tunit_cube(vals, renderer.M) + #raise RuntimeError('WTF: p1=%s'%p1) avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \ p1, p2, p3, p4 in self._PLANES] - highs = [avgz[2*i] < avgz[2*i+1] for i in range(3)] + highs = np.array([avgz[2*i] < avgz[2*i+1] for i in range(3)]) # Draw plane info = self._AXINFO[self.adir] @@ -178,18 +180,14 @@ self.pane.draw(renderer) # Determine grid lines - minmax = [] - for i, val in enumerate(highs): - if val: - minmax.append(maxs[i]) - else: - minmax.append(mins[i]) + minmax = np.where(highs, maxs, mins) # Draw main axis line juggled = art3d.juggle_axes(0, 2, 1, self.adir) - edgep1 = copy.copy(minmax) + edgep1 = minmax.copy() edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) - edgep2 = copy.copy(edgep1) + + edgep2 = edgep1.copy() edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) @@ -198,15 +196,17 @@ # Grid points where the planes meet xyz0 = [] for val in majorLocs: - coord = copy.copy(minmax) + coord = minmax.copy() coord[index] = val xyz0.append(coord) # Draw labels dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] - lxyz = [(v1 + v2) / 2 for v1, v2 in zip(edgep1, edgep2)] - labeldeltas = [1.3 * x for x in deltas] + + lxyz = 0.5*(edgep1 + edgep2) + + labeldeltas = 1.3 * deltas lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) @@ -293,7 +293,7 @@ def get_data_interval(self): 'return the Interval instance for this axis data limits' return self.axes.xy_dataLim.intervaly - + class ZAxis(Axis): def get_data_interval(self): 'return the Interval instance for this axis data limits' Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py 2009-08-08 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py 2009-08-08 11:25:32 UTC (rev 7427) @@ -10,15 +10,8 @@ import numpy as np import numpy.linalg as linalg -def cross(a, b): - """ - Cross product of two vectors - A x B = <Ay*Bz - Az*By, Az*Bx - Ax*Bz, Ax*By - Ay*Bx> - a x b = [a2b3 - a3b2, a3b1 - a1b3, a1b2 - a2b1] - """ - return np.array([a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], \ - a[0]*b[1] - a[1]*b[0]]) + def line2d(p0, p1): """ Return 2D equation of line in the form ax+by+c = 0 @@ -130,9 +123,9 @@ ## old n = n / mod(n) - u = cross(V, n) + u = np.cross(V, n) u = u / mod(u) - v = cross(n, u) + v = np.cross(n, u) Mr = [[u[0],u[1],u[2],0], [v[0],v[1],v[2],0], [n[0],n[1],n[2],0], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |