From: <he...@us...> - 2009-07-14 21:11:59
|
Revision: 7260 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7260&view=rev Author: heeres Date: 2009-07-14 21:11:53 +0000 (Tue, 14 Jul 2009) Log Message: ----------- Fix mplot3d bug with empty lists thanks to Ryan Wagner. Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-07-14 19:21:47 UTC (rev 7259) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-07-14 21:11:53 UTC (rev 7260) @@ -633,11 +633,14 @@ shade = np.array(shade) mask = ~np.isnan(shade) - norm = Normalize(min(shade[mask]), max(shade[mask])) - color = color.copy() - color[3] = 1 - colors = [color * (0.5 + norm(v) * 0.5) for v in shade] + if len(shade[mask]) > 0: + norm = Normalize(min(shade[mask]), max(shade[mask])) + color = color.copy() + color[3] = 1 + colors = [color * (0.5 + norm(v) * 0.5) for v in shade] + else: + colors = color.copy() return colors @@ -707,6 +710,12 @@ polyverts = [] normals = [] nsteps = round(len(topverts[0]) / stride) + if nsteps <= 1: + if len(topverts[0]) > 1: + nsteps = 2 + else: + continue + stepsize = (len(topverts[0]) - 1) / (nsteps - 1) for i in range(int(round(nsteps)) - 1): i1 = int(round(i * stepsize)) @@ -719,11 +728,11 @@ 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, - edgecolors=colors2) + edgecolors=colors2) self.add_collection3d(polycol) for col in colls: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <he...@us...> - 2010-03-20 00:29:27
|
Revision: 8200 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8200&view=rev Author: heeres Date: 2010-03-20 00:29:19 +0000 (Sat, 20 Mar 2010) Log Message: ----------- Add view angle patch + comment Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2010-03-19 17:12:41 UTC (rev 8199) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2010-03-20 00:29:19 UTC (rev 8200) @@ -59,16 +59,16 @@ self.fig = fig self._cids = [] - azim = kwargs.pop('azim', -60) - elev = kwargs.pop('elev', 30) + self.initial_azim = kwargs.pop('azim', -60) + self.initial_elev = kwargs.pop('elev', 30) self.xy_viewLim = unit_bbox() self.zz_viewLim = unit_bbox() self.xy_dataLim = unit_bbox() self.zz_dataLim = unit_bbox() - # inihibit autoscale_view until the axises are defined + # inihibit autoscale_view until the axes are defined # they can't be defined until Axes.__init__ has been called - self.view_init(elev, azim) + self.view_init(self.initial_elev, self.initial_azim) self._ready = 0 Axes.__init__(self, self.fig, rect, frameon=True, @@ -272,11 +272,31 @@ def panpy(self, numsteps): print 'numsteps', numsteps - def view_init(self, elev, azim): + def view_init(self, elev=None, azim=None): + """ + Set the elevation and azimuth of the axes. + + This can be used to rotate the axes programatically. + + 'elev' stores the elevation angle in the z plane. + 'azim' stores the azimuth angle in the x,y plane. + + if elev or azim are None (default), then the initial value + is used which was specified in the :class:`Axes3D` constructor. + """ + self.dist = 10 - self.elev = elev - self.azim = azim - + + if elev is None: + self.elev = self.initial_elev + else: + self.elev = elev + + if azim is None: + self.azim = self.initial_azim + else: + self.azim = azim + def get_proj(self): """Create the projection matrix from the current viewing position. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2010-07-05 01:27:00
|
Revision: 8493 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8493&view=rev Author: jdh2358 Date: 2010-07-05 01:26:53 +0000 (Mon, 05 Jul 2010) Log Message: ----------- Applied Ben's rotate button patch for axes3d Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2010-07-05 01:25:09 UTC (rev 8492) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2010-07-05 01:26:53 UTC (rev 8493) @@ -446,7 +446,7 @@ if self.M is None: return '' - if self.button_pressed == 1: + if self.button_pressed in self._rotate_btn: return 'azimuth=%d deg, elevation=%d deg ' % (self.azim, self.elev) # ignore xd and yd and display angles instead This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wea...@us...> - 2011-01-03 21:53:16
|
Revision: 8878 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8878&view=rev Author: weathergod Date: 2011-01-03 21:53:09 +0000 (Mon, 03 Jan 2011) Log Message: ----------- Significant speedups to plot_surface function in mplot3d. Thanks to Justin Peel! Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2011-01-03 21:36:37 UTC (rev 8877) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2011-01-03 21:53:09 UTC (rev 8878) @@ -696,7 +696,6 @@ had_data = self.has_data() rows, cols = Z.shape - tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z) rstride = kwargs.pop('rstride', 10) cstride = kwargs.pop('cstride', 10) @@ -719,21 +718,27 @@ fcolors = self._shade_colors_lightsource(Z, cmap, lightsource) polys = [] - normals = [] + # Only need these vectors to shade if there is no cmap + if cmap is None and shade : + totpts = int(np.ceil(float(rows - 1) / rstride) * + np.ceil(float(cols - 1) / cstride)) + v1 = np.empty((totpts, 3)) + v2 = np.empty((totpts, 3)) + # This indexes the vertex points + which_pt = 0 + + #colset contains the data for coloring: either average z or the facecolor colset = [] - for rs in np.arange(0, rows-1, rstride): - for cs in np.arange(0, cols-1, cstride): + for rs in xrange(0, rows-1, rstride): + for cs in xrange(0, cols-1, cstride): ps = [] - corners = [] - for a, ta in [(X, tX), (Y, tY), (Z, tZ)]: - ztop = a[rs][cs:min(cols, cs+cstride+1)] - zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)] - zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):] - zbase = zbase[::-1] - zright = ta[cs][rs:min(rows, rs+rstride+1):] - zright = zright[::-1] - corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]]) + for a in (X, Y, Z) : + ztop = a[rs,cs:min(cols, cs+cstride+1)] + zleft = a[rs+1:min(rows, rs+rstride+1), + min(cols-1, cs+cstride)] + zbase = a[min(rows-1, rs+rstride), cs:min(cols, cs+cstride+1):][::-1] + zright = a[rs:min(rows-1, rs+rstride):, cs][::-1] z = np.concatenate((ztop, zleft, zbase, zright)) ps.append(z) @@ -741,13 +746,8 @@ # are removed here. ps = zip(*ps) lastp = np.array([]) - ps2 = [] - avgzsum = 0.0 - for p in ps: - if p != lastp: - ps2.append(p) - lastp = p - avgzsum += p[2] + ps2 = [ps[0]] + [ps[i] for i in xrange(1, len(ps)) if ps[i] != ps[i-1]] + avgzsum = sum(p[2] for p in ps2) polys.append(ps2) if fcolors is not None: @@ -758,9 +758,13 @@ # Only need vectors to shade if no cmap if cmap is None and shade: i1, i2, i3 = 0, int(len(ps2)/3), int(2*len(ps2)/3) - v1 = np.array(ps2[i1]) - np.array(ps2[i2]) - v2 = np.array(ps2[i2]) - np.array(ps2[i3]) - normals.append(np.cross(v1, v2)) + v1[which_pt] = np.array(ps2[i1]) - np.array(ps2[i2]) + v2[which_pt] = np.array(ps2[i2]) - np.array(ps2[i3]) + which_pt += 1 + if cmap is None and shade: + normals = np.cross(v1, v2) + else : + normals = [] polyc = art3d.Poly3DCollection(polys, *args, **kwargs) @@ -808,12 +812,8 @@ *color* can also be an array of the same length as *normals*. ''' - shade = [] - for n in normals: - n = n / proj3d.mod(n) - shade.append(np.dot(n, [-1, -1, 0.5])) - - shade = np.array(shade) + shade = np.array([np.dot(n / proj3d.mod(n), [-1, -1, 0.5]) + for n in normals]) mask = ~np.isnan(shade) if len(shade[mask]) > 0: @@ -821,11 +821,10 @@ if art3d.iscolor(color): color = color.copy() color[3] = 1 - colors = [color * (0.5 + norm(v) * 0.5) for v in shade] + colors = np.outer(0.5 + norm(shade) * 0.5, color) else: - colors = [np.array(colorConverter.to_rgba(c)) * \ - (0.5 + norm(v) * 0.5) \ - for c, v in zip(color, shade)] + colors = colorConverter.to_rgba_array(color) * \ + (0.5 + 0.5 * norm(shade)[:, np.newaxis]) else: colors = color.copy() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wea...@us...> - 2011-01-21 20:39:00
|
Revision: 8930 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8930&view=rev Author: weathergod Date: 2011-01-21 20:38:54 +0000 (Fri, 21 Jan 2011) Log Message: ----------- Fixing polygon shading in mplot3d and simultaneously allowing users to specify alpha values for 3d polygons. (Shading calculation was applied to the rgba array instead of just rgb) Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2011-01-18 22:12:52 UTC (rev 8929) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2011-01-21 20:38:54 UTC (rev 8930) @@ -818,13 +818,13 @@ if len(shade[mask]) > 0: norm = Normalize(min(shade[mask]), max(shade[mask])) - if art3d.iscolor(color): - color = color.copy() - color[3] = 1 - colors = np.outer(0.5 + norm(shade) * 0.5, color) - else: - colors = colorConverter.to_rgba_array(color) * \ - (0.5 + 0.5 * norm(shade)[:, np.newaxis]) + color = colorConverter.to_rgba_array(color) + # shape of color should be (M, 4) (where M is number of faces) + # shape of shade should be (M,) + # colors should have final shape of (M, 4) + alpha = color[:, 3] + colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color + colors[:, 3] = alpha else: colors = color.copy() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |