From: <md...@us...> - 2007-10-12 12:27:49
|
Revision: 3937 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3937&view=rev Author: mdboom Date: 2007-10-12 05:27:25 -0700 (Fri, 12 Oct 2007) Log Message: ----------- First pass through all of the examples -- not all working yet, though. (See PASSED_DEMOS). Modified Paths: -------------- branches/transforms/PASSED_DEMOS branches/transforms/examples/to_numeric.py branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/collections.py branches/transforms/lib/matplotlib/figure.py branches/transforms/lib/matplotlib/patches.py branches/transforms/lib/matplotlib/path.py branches/transforms/lib/matplotlib/projections/polar.py branches/transforms/lib/matplotlib/pyplot.py branches/transforms/lib/matplotlib/quiver.py branches/transforms/lib/matplotlib/table.py branches/transforms/lib/matplotlib/widgets.py branches/transforms/src/_backend_agg.cpp Modified: branches/transforms/PASSED_DEMOS =================================================================== --- branches/transforms/PASSED_DEMOS 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/PASSED_DEMOS 2007-10-12 12:27:25 UTC (rev 3937) @@ -148,63 +148,63 @@ pcolor_log.py O pcolor_nonuniform.py O pcolor_small.py O -pick_event_demo2.py -pick_event_demo.py -pie_demo.py -plotfile_demo.py -polar_bar.py -polar_demo.py -polar_legend.py -polar_scatter.py -poly_editor.py -poormans_contour.py +pick_event_demo2.py O +pick_event_demo.py O +pie_demo.py O +plotfile_demo.py O +polar_bar.py O +polar_demo.py O +polar_legend.py O +polar_scatter.py O +poly_editor.py [NEEDS OVERHAUL] +poormans_contour.py O printing_in_wx.py -print_stdout.py -psd_demo.py +print_stdout.py [BROKEN?] +psd_demo.py O pstest.py pylab_with_gtk.py -pythonic_matplotlib.py -quadmesh_demo.py -quiver_demo.py -rc_traits.py -scatter_custom_symbol.py -scatter_demo2.py -scatter_demo.py -scatter_masked.py -scatter_profile.py -scatter_star_poly.py -set_and_get.py -shared_axis_across_figures.py -shared_axis_demo.py -simple3d_oo.py -simple3d.py -simple_plot_fps.py -simple_plot.py -specgram_demo.py -spy_demos.py -stem_plot.py -step_demo.py -stock_demo.py -strip_chart_demo.py -subplot_demo.py -subplots_adjust.py -subplot_toolbar.py -system_monitor.py -table_demo.py -tex_demo.py -text_handles.py -text_rotation.py -text_themes.py -tex_unicode_demo.py -toggle_images.py -to_numeric.py +pythonic_matplotlib.py O +quadmesh_demo.py [MASKED VALUES NOT QUITE RIGHT] +quiver_demo.py [SEGFAULTS] +rc_traits.py [N/A] +scatter_custom_symbol.py O +scatter_demo2.py O +scatter_demo.py O +scatter_masked.py O +scatter_profile.py O +scatter_star_poly.py O [SOME BUGS IN TRUNK -- FIXED ON BRANCH] +set_and_get.py O +shared_axis_across_figures.py O +shared_axis_demo.py O +simple3d_oo.py [PUNTING ON 3D FOR NOW] +simple3d.py [PUNTING ON 3D FOR NOW] +simple_plot_fps.py O +simple_plot.py O +specgram_demo.py O +spy_demos.py O +stem_plot.py O +step_demo.py O +stock_demo.py O +strip_chart_demo.py [REQUIRES GTK] +subplot_demo.py O +subplots_adjust.py O +subplot_toolbar.py O +system_monitor.py O +table_demo.py +tex_demo.py O +text_handles.py O +text_rotation.py O +text_themes.py O +tex_unicode_demo.py O +toggle_images.py [???] +to_numeric.py [REQUIRES PIL] transoffset.py -two_scales.py -unicode_demo.py -vertical_ticklabels.py -vline_demo.py -webapp_demo.py -wxcursor_demo.py -xcorr_demo.py -zoom_window.py -zorder_demo.py +two_scales.py O +unicode_demo.py O +vertical_ticklabels.py O +vline_demo.py O +webapp_demo.py +wxcursor_demo.py +xcorr_demo.py O +zoom_window.py O +zorder_demo.py O Modified: branches/transforms/examples/to_numeric.py =================================================================== --- branches/transforms/examples/to_numeric.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/examples/to_numeric.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -17,7 +17,7 @@ s = agg.tostring_rgb() # get the width and the height to resize the matrix -l,b,w,h = agg.figure.bbox.get_bounds() +l,b,w,h = agg.figure.bbox.bounds w, h = int(w), int(h) Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/axes.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -1196,9 +1196,9 @@ len(self.lines)==0 and len(self.patches)==0)): - if scalex: self.set_xbound(self.dataLim.intervalx().get_bounds()) + if scalex: self.set_xbound(self.dataLim.intervalx) - if scaley: self.set_ybound(self.dataLim.intervaly().get_bounds()) + if scaley: self.set_ybound(self.dataLim.intervaly) return if scalex: @@ -4107,7 +4107,6 @@ if sym is not None: if symstyle==0: - collection = mcoll.RegularPolyCollection( self.figure.dpi, numsides, rotation, scales, @@ -4143,7 +4142,7 @@ verts /= rescale scales = npy.asarray(scales) - scales = npy.sqrt(scales * self.figure.dpi.get() / 72.) + scales = npy.sqrt(scales * self.figure.dpi / 72.) if len(scales)==1: verts = [scales[0]*verts] else: @@ -4858,7 +4857,7 @@ self.set_xlabel('Frequency') self.set_ylabel('Power Spectrum (dB)') self.grid(True) - vmin, vmax = self.viewLim.intervaly().get_bounds() + vmin, vmax = self.viewLim.intervaly intv = vmax-vmin logi = int(npy.log10(intv)) if logi==0: logi=.1 Modified: branches/transforms/lib/matplotlib/collections.py =================================================================== --- branches/transforms/lib/matplotlib/collections.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/collections.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -78,9 +78,9 @@ **kwargs ): """ - Create a PatchCollection + Create a Collection - %(PatchCollection)s + %(Collection)s """ artist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) @@ -103,8 +103,9 @@ self._uniform_offsets = None self._offsets = npy.zeros((1, 2)) if offsets is not None: -# if len(offsets.shape) == 1: -# offsets = offsets[npy.newaxis,:] # Make it Nx2. + offsets = npy.asarray(offsets, npy.float_) + if len(offsets.shape) == 1: + offsets = offsets[npy.newaxis,:] # Make it Nx2. if transOffset is not None: Affine2D = transforms.Affine2D self._offsets = offsets @@ -171,7 +172,10 @@ if not transform.is_affine: paths = [transform.transform_path_non_affine(path) for path in paths] transform = transform.get_affine() - + if not transOffset.is_affine: + offsets = transOffset.transform_non_affine(offsets) + transOffset = transOffset.get_affine() + renderer.draw_path_collection( transform, self.clipbox, clippath, clippath_trans, paths, self.get_transforms(), @@ -353,7 +357,7 @@ #print 'update_scalarmappable: self._A', self._A if self._A is None: return if len(self._A.shape)>1: - raise ValueError('PatchCollections can only map rank 1 arrays') + raise ValueError('Collections can only map rank 1 arrays') if len(self._facecolors): self._facecolors = self.to_rgba(self._A, self._alpha) else: @@ -410,33 +414,45 @@ (0, 2) .. (0, meshWidth), (1, 0), (1, 1), and so on. """ def __init__(self, meshWidth, meshHeight, coordinates, showedges): + Path = path.Path + Collection.__init__(self) self._meshWidth = meshWidth self._meshHeight = meshHeight self._coordinates = coordinates self._showedges = showedges + + # MGDTODO: Numpify + coordinates = coordinates.reshape((meshHeight + 1, meshWidth + 1, 2)) + c = coordinates + paths = [] + # We could let the Path constructor generate the codes for us, + # but this is faster, since we know they'll always be the same + codes = npy.array([Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO]) + for m in xrange(meshHeight): + for n in xrange(meshWidth): + paths.append(Path( + [c[m , n], + c[m , n+1], + c[m+1, n+1], + c[m+1, n]], + codes)) + self._paths = paths + + def get_paths(self, dataTrans=None): + return self._paths - def get_verts(self, dataTrans=None): - return self._coordinates; - def draw(self, renderer): - # does not call update_scalarmappable, need to update it - # when creating/changing ****** Why not? speed? - if not self.get_visible(): return - transform = self.get_transform() - transoffset = self._transOffset - transform.freeze() - transoffset.freeze() - #print 'QuadMesh draw' self.update_scalarmappable() ####################### - renderer.draw_quad_mesh( self._meshWidth, self._meshHeight, - self._facecolors, self._coordinates[:,0], - self._coordinates[:, 1], self.clipbox, transform, - self._offsets, transoffset, self._showedges) - transform.thaw() - transoffset.thaw() + self._linewidths = (1,) + if self._showedges: + self._edgecolors = npy.array([[0.0, 0.0, 0.0, 1.0]], npy.float_) + else: + self._edgecolors = self._facecolors + Collection.draw(self, renderer) + class PolyCollection(Collection): def __init__(self, verts, **kwargs): """ @@ -476,6 +492,8 @@ __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd class RegularPolyCollection(Collection): + _path_generator = path.Path.unit_regular_polygon + def __init__(self, dpi, numsides, @@ -514,18 +532,16 @@ offsets = offsets, transOffset = ax.transData, ) - - """ Collection.__init__(self,**kwargs) self._sizes = sizes self._dpi = dpi - self._paths = [path.Path.unit_regular_polygon(numsides)] + self._paths = [self._path_generator(numsides)] # sizes is the area of the circle circumscribing the polygon # in points^2 self._transforms = [ - transforms.Affine2D().rotate(rotation).scale( - (math.sqrt(x) * self._dpi / 72.0) * (1.0 / math.sqrt(math.pi))) + transforms.Affine2D().rotate(-rotation).scale( + (math.sqrt(x) * self._dpi / 72.0) / math.sqrt(math.pi)) for x in sizes] self.set_transform(transforms.IdentityTransform()) @@ -554,72 +570,13 @@ class StarPolygonCollection(RegularPolyCollection): - def __init__(self, - dpi, - numsides, - rotation = 0 , - sizes = (1,), - **kwargs): - """ - Draw a regular star like Polygone with numsides. - - * dpi is the figure dpi instance, and is required to do the - area scaling. - - * numsides: the number of sides of the polygon - - * sizes gives the area of the circle circumscribing the - regular polygon in points^2 - - * rotation is the rotation of the polygon in radians - - %(Collection)s - """ - - RegularPolyCollection.__init__(self, dpi, numsides, rotation, sizes, **kwargs) - __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd - - def _update_verts(self): - scale = 1.0/math.sqrt(math.pi) - ns2 = self.numsides*2 - r = scale*npy.ones(ns2) - r[1::2] *= 0.5 - theta = (math.pi/self.numsides)*npy.arange(ns2) + self.rotation - self._verts = zip( r*npy.sin(theta), r*npy.cos(theta) ) - + _path_generator = path.Path.unit_regular_star + + class AsteriskPolygonCollection(RegularPolyCollection): - def __init__(self, - dpi, - numsides, - rotation = 0 , - sizes = (1,), - **kwargs): - """ - Draw a regular asterisk Polygone with numsides spikes. - - * dpi is the figure dpi instance, and is required to do the - area scaling. - - * numsides: the number of spikes of the polygon - - * sizes gives the area of the circle circumscribing the - regular polygon in points^2 - - * rotation is the rotation of the polygon in radians - - %(Collection)s - """ - - RegularPolyCollection.__init__(self, dpi, numsides, rotation, sizes, **kwargs) - __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd - - def _update_verts(self): - scale = 1.0/math.sqrt(math.pi) - r = scale*npy.ones(self.numsides*2) - r[1::2] = 0 - theta = (math.pi/self.numsides)*npy.arange(2*self.numsides) + self.rotation - self._verts = zip( r*npy.sin(theta), r*npy.cos(theta) ) - + _path_generator = path.Path.unit_regular_asterisk + + class LineCollection(Collection, cm.ScalarMappable): """ All parameters must be sequences or scalars; if scalars, they will Modified: branches/transforms/lib/matplotlib/figure.py =================================================================== --- branches/transforms/lib/matplotlib/figure.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/figure.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -106,8 +106,7 @@ class Figure(Artist): def __str__(self): - return "Figure(%gx%g)"%(self.bbox.max) - # return "Figure(%gx%g)"%(self.figwidth.get(),self.figheight.get()) + return "Figure(%gx%g)" % tuple(self.bbox.size) def __init__(self, figsize = None, # defaults to rc figure.figsize Modified: branches/transforms/lib/matplotlib/patches.py =================================================================== --- branches/transforms/lib/matplotlib/patches.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/patches.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -495,7 +495,7 @@ A general polygon patch. """ def __str__(self): - return "Poly(%g,%g)"%self.xy[0] + return "Poly(%g, %g)" % tuple(self._path.vertices[0]) def __init__(self, xy, **kwargs): """ @@ -506,11 +506,15 @@ See Patch documentation for additional kwargs """ Patch.__init__(self, **kwargs) + self.xy = xy self._path = Path(xy, closed=True) __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd def get_path(self): return self._path + + def update(self): + self._path = Path(self.xy, closed=True) class Wedge(Patch): def __str__(self): Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/path.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -93,7 +93,7 @@ codes = self.LINETO * npy.ones( vertices.shape[0] + 1, self.code_type) codes[0] = self.MOVETO - codes[-1] = self.LINETO + codes[-1] = self.CLOSEPOLY vertices = npy.concatenate((vertices, [vertices[0]])) else: codes = self.LINETO * npy.ones( @@ -214,7 +214,7 @@ if cls._unit_rectangle is None: cls._unit_rectangle = \ Path([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]) - return cls._unit_rectangle + return cls._unit_rectangle unit_rectangle = classmethod(unit_rectangle) _unit_regular_polygons = {} @@ -237,6 +237,37 @@ return path unit_regular_polygon = classmethod(unit_regular_polygon) + _unit_regular_stars = {} + #@classmethod + def unit_regular_star(cls, numVertices, innerCircle=0.5): + """ + Returns a Path for a unit regular star with the given + numVertices and radius of 1.0, centered at (0, 0). + """ + path = cls._unit_regular_stars.get((numVertices, innerCircle)) + if path is None: + ns2 = numVertices * 2 + theta = (2*npy.pi/ns2 * npy.arange(ns2)) + # This initial rotation is to make sure the polygon always + # "points-up" + theta += npy.pi / 2.0 + r = npy.ones(ns2) + r[1::2] = innerCircle + verts = npy.vstack((r*npy.cos(theta), r*npy.sin(theta))).transpose() + path = Path(verts) + cls._unit_regular_polygons[(numVertices, innerCircle)] = path + return path + unit_regular_star = classmethod(unit_regular_star) + + #@classmethod + def unit_regular_asterisk(cls, numVertices): + """ + Returns a Path for a unit regular asterisk with the given + numVertices and radius of 1.0, centered at (0, 0). + """ + return cls.unit_regular_star(numVertices, 0.0) + unit_regular_asterisk = classmethod(unit_regular_asterisk) + _unit_circle = None #@classmethod def unit_circle(cls): Modified: branches/transforms/lib/matplotlib/projections/polar.py =================================================================== --- branches/transforms/lib/matplotlib/projections/polar.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/projections/polar.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -55,8 +55,7 @@ transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ def transform_path(self, path): - if len(path.vertices) == 2: - path = path.interpolated(self._resolution) + path = path.interpolated(self._resolution) return Path(self.transform(path.vertices), path.codes) transform_path.__doc__ = Transform.transform_path.__doc__ Modified: branches/transforms/lib/matplotlib/pyplot.py =================================================================== --- branches/transforms/lib/matplotlib/pyplot.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/pyplot.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -2,7 +2,7 @@ import matplotlib from matplotlib import _pylab_helpers -from matplotlib.cbook import dedent, silent_list +from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike from matplotlib.figure import Figure, figaspect from matplotlib.backend_bases import FigureCanvasBase from matplotlib.image import imread as _imread @@ -1232,9 +1232,9 @@ def getname_val(identifier): 'return the name and column data for identifier' - if cbook.is_string_like(identifier): + if is_string_like(identifier): return identifier, r[identifier] - elif cbook.is_numlike(identifier): + elif is_numlike(identifier): name = r.dtype.names[int(identifier)] return name, r[name] else: Modified: branches/transforms/lib/matplotlib/quiver.py =================================================================== --- branches/transforms/lib/matplotlib/quiver.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/quiver.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -168,8 +168,7 @@ self.coord = kw.pop('coordinates', 'axes') self.color = kw.pop('color', None) self.label = label - self.labelsep = (transforms.Value(kw.pop('labelsep', 0.1)) - * Q.ax.figure.dpi) + self.labelsep = (kw.pop('labelsep', 0.1) * Q.ax.figure.dpi) self.labelpos = kw.pop('labelpos', 'N') self.labelcolor = kw.pop('labelcolor', None) self.fontproperties = kw.pop('fontproperties', dict()) @@ -281,8 +280,8 @@ self.pivot = kw.pop('pivot', 'tail') kw.setdefault('facecolors', self.color) kw.setdefault('linewidths', (0,)) - collections.PolyCollection.__init__(self, None, offsets=zip(X, Y), - transOffset=ax.transData, **kw) + collections.PolyCollection.__init__(self, [], offsets=zip(X, Y), + transOffset=ax.transData, **kw) self.polykw = kw self.set_UVC(U, V, C) self._initialized = False @@ -324,7 +323,7 @@ if not self._initialized: trans = self._set_transform() ax = self.ax - sx, sy = trans.inverse_xy_tup((ax.bbox.width(), ax.bbox.height())) + sx, sy = trans.transform_point((ax.bbox.width, ax.bbox.height)) self.span = sx sn = max(8, min(25, math.sqrt(self.N))) if self.width is None: @@ -362,17 +361,17 @@ dx = dx1/dx0 else: if self.units == 'width': - dx = ax.bbox.ur().x() - ax.bbox.ll().x() + dx = ax.bbox.width elif self.units == 'height': - dx = ax.bbox.ur().y() - ax.bbox.ll().y() + dx = ax.bbox.height elif self.units == 'dots': dx = transforms.Value(1) elif self.units == 'inches': dx = ax.figure.dpi else: raise ValueError('unrecognized units') - bb = transforms.Bbox(transforms.origin(), transforms.Point(dx, dx)) - trans = transforms.get_bbox_transform(transforms.unit_bbox(), bb) + bb = transforms.Bbox.from_lbrt(0, 0, dx, dx) + trans = transforms.BboxTransform(transforms.Bbox.unit(), bb) self.set_transform(trans) return trans Modified: branches/transforms/lib/matplotlib/table.py =================================================================== --- branches/transforms/lib/matplotlib/table.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/table.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -216,7 +216,7 @@ self._cells[(row, col)] = cell def _approx_text_height(self): - return self.FONTSIZE/72.0*self.figure.dpi.get()/self._axes.bbox.height() * 1.2 + return self.FONTSIZE/72.0*self.figure.dpi/self._axes.bbox.height * 1.2 def draw(self, renderer): # Need a renderer to do hit tests on mouseevent; assume the last one will do Modified: branches/transforms/lib/matplotlib/widgets.py =================================================================== --- branches/transforms/lib/matplotlib/widgets.py 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/lib/matplotlib/widgets.py 2007-10-12 12:27:25 UTC (rev 3937) @@ -242,6 +242,7 @@ def set_val(self, val): self.poly.xy[-1] = val, 0 self.poly.xy[-2] = val, 1 + self.poly.update() self.valtext.set_text(self.valfmt%val) if self.drawon: self.ax.figure.canvas.draw() self.val = val Modified: branches/transforms/src/_backend_agg.cpp =================================================================== --- branches/transforms/src/_backend_agg.cpp 2007-10-11 22:09:18 UTC (rev 3936) +++ branches/transforms/src/_backend_agg.cpp 2007-10-12 12:27:25 UTC (rev 3937) @@ -832,6 +832,8 @@ // Render face if (face.first) { + theRasterizer->add_path(curve); + if (gc.isaa) { if (has_clippath) { pixfmt_amask_type pfa(*pixFmt, *alphaMask); @@ -841,7 +843,6 @@ agg::render_scanlines(*theRasterizer, *slineP8, ren); } else { rendererAA->color(face.second); - theRasterizer->add_path(curve); agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); } } else { @@ -853,7 +854,6 @@ agg::render_scanlines(*theRasterizer, *slineP8, ren); } else { rendererBin->color(face.second); - theRasterizer->add_path(curve); agg::render_scanlines(*theRasterizer, *slineP8, *rendererBin); } } @@ -945,7 +945,7 @@ Py::SeqBase<Py::Object> paths = args[4]; Py::SeqBase<Py::Object> transforms_obj = args[5]; Py::Object offsets_obj = args[6]; - agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7], false); + agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7]); Py::Object facecolors_obj = args[8]; Py::Object edgecolors_obj = args[9]; Py::SeqBase<Py::Float> linewidths = args[10]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |