From: <md...@us...> - 2008-07-17 18:26:45
|
Revision: 5777 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5777&view=rev Author: mdboom Date: 2008-07-17 18:26:41 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Fix non-linear scaling with pcolormesh and non-Agg backends. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-07-17 18:25:20 UTC (rev 5776) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-07-17 18:26:41 UTC (rev 5777) @@ -10,6 +10,7 @@ """ import math, warnings import numpy as np +import numpy.ma as ma import matplotlib as mpl import matplotlib.cbook as cbook import matplotlib.colors as _colors # avoid conflict with kwarg @@ -468,7 +469,11 @@ """ Path = mpath.Path - c = coordinates + if ma.isMaskedArray(coordinates): + c = coordinates.data + else: + c = coordinates + # 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 = np.array( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-07-20 07:14:52
|
Revision: 5795 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5795&view=rev Author: efiring Date: 2008-07-20 07:14:46 +0000 (Sun, 20 Jul 2008) Log Message: ----------- In collections draw methods, use get_facecolor and get_edgecolor. The logic for edgecolors='face' is moved into get_edgecolor so that it will return the color(s) that will actually be used. Using the getters means that a derived class can override them to add more logic to the choice of colors. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-07-20 02:59:00 UTC (rev 5794) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-07-20 07:14:46 UTC (rev 5795) @@ -184,16 +184,12 @@ offsets = transOffset.transform_non_affine(offsets) transOffset = transOffset.get_affine() - if self._edgecolors == 'face': - edgecolors = self._facecolors - else: - edgecolors = self._edgecolors renderer.draw_path_collection( transform.frozen(), self.clipbox, clippath, clippath_trans, paths, self.get_transforms(), offsets, transOffset, - self._facecolors, edgecolors, self._linewidths, + self.get_facecolor(), self.get_edgecolor(), self._linewidths, self._linestyles, self._antialiaseds) renderer.close_group(self.__class__.__name__) @@ -315,7 +311,10 @@ get_facecolors = get_facecolor def get_edgecolor(self): - return self._edgecolors + if self._edgecolors == 'face': + return self.get_facecolors() + else: + return self._edgecolors get_edgecolors = get_edgecolor def set_edgecolor(self, c): @@ -534,7 +533,7 @@ renderer.draw_quad_mesh( transform.frozen(), self.clipbox, clippath, clippath_trans, self._meshWidth, self._meshHeight, coordinates, - offsets, transOffset, self._facecolors, self._antialiased, + offsets, transOffset, self.get_facecolor(), self._antialiased, self._showedges) renderer.close_group(self.__class__.__name__) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pki...@us...> - 2008-07-26 19:24:30
|
Revision: 5891 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5891&view=rev Author: pkienzle Date: 2008-07-26 19:24:28 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Fix contains() for collections, moving common code from draw() into a function Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-07-26 19:22:44 UTC (rev 5890) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-07-26 19:24:28 UTC (rev 5891) @@ -148,9 +148,9 @@ result = result.inverse_transformed(transData) return result - def draw(self, renderer): - if not self.get_visible(): return - renderer.open_group(self.__class__.__name__) + def _prepare_points(self): + """Point prep for drawing and hit testing""" + transform = self.get_transform() transOffset = self._transOffset offsets = self._offsets @@ -171,12 +171,6 @@ offsets = np.asarray(offsets, np.float_) - self.update_scalarmappable() - - clippath, clippath_trans = self.get_transformed_clip_path_and_affine() - if clippath_trans is not None: - clippath_trans = clippath_trans.frozen() - if not transform.is_affine: paths = [transform.transform_path_non_affine(path) for path in paths] transform = transform.get_affine() @@ -184,7 +178,20 @@ offsets = transOffset.transform_non_affine(offsets) transOffset = transOffset.get_affine() + return transform, transOffset, offsets, paths + def draw(self, renderer): + if not self.get_visible(): return + renderer.open_group(self.__class__.__name__) + + self.update_scalarmappable() + + clippath, clippath_trans = self.get_transformed_clip_path_and_affine() + if clippath_trans is not None: + clippath_trans = clippath_trans.frozen() + + transform, transOffset, offsets, paths = self._prepare_points() + renderer.draw_path_collection( transform.frozen(), self.clipbox, clippath, clippath_trans, paths, self.get_transforms(), @@ -201,18 +208,14 @@ item in itemlist contains the event. """ if callable(self._contains): return self._contains(self,mouseevent) + if not self.get_visible(): return False,{} - transform = self.get_transform() - paths = self.get_paths() - if not transform.is_affine: - paths = [transform.transform_path_non_affine(path) for path in paths] - transform = transform.get_affine() + transform, transOffset, offsets, paths = self._prepare_points() ind = mpath.point_in_path_collection( mouseevent.x, mouseevent.y, self._pickradius, transform.frozen(), paths, self.get_transforms(), - np.asarray(self._offsets, np.float_), - self._transOffset.frozen(), len(self._facecolors)) + offsets, transOffset, len(self._facecolors)>0) return len(ind)>0,dict(ind=ind) def set_pickradius(self,pickradius): self.pickradius = 5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-07-27 02:11:07
|
Revision: 5899 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5899&view=rev Author: efiring Date: 2008-07-27 02:11:05 +0000 (Sun, 27 Jul 2008) Log Message: ----------- Fix PolyCollection sizes kwarg docstring Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-07-27 01:17:54 UTC (rev 5898) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-07-27 02:11:05 UTC (rev 5899) @@ -573,8 +573,14 @@ *verts_i* is a sequence of *xy* tuples of vertices, or an equivalent :mod:`numpy` array of shape (*nv*, 2). - *sizes* gives the area of the circle circumscribing the - polygon in points^2. + *sizes* is *None* (default) or a sequence of floats that + scale the corresponding *verts_i*. The scaling is applied + before the Artist master transform; if the latter is an identity + transform, then the overall scaling is such that if + *verts_i* specify a unit square, then *sizes_i* is the area + of that square in points^2. + If len(*sizes*) < *nv*, the additional values will be + taken cyclically from the array. *closed*, when *True*, will explicitly close the polygon. @@ -601,8 +607,6 @@ return self._paths def draw(self, renderer): - # sizes is the area of the circle circumscribing the polygon - # in points^2 if self._sizes is not None: self._transforms = [ transforms.Affine2D().scale( @@ -679,8 +683,6 @@ __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd def draw(self, renderer): - # sizes is the area of the circle circumscribing the polygon - # in points^2 self._transforms = [ transforms.Affine2D().rotate(-self._rotation).scale( (np.sqrt(x) * self.figure.dpi / 72.0) / np.sqrt(np.pi)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2008-09-04 19:52:45
|
Revision: 6064 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6064&view=rev Author: ryanmay Date: 2008-09-04 19:52:42 +0000 (Thu, 04 Sep 2008) Log Message: ----------- Fix typo (iterator()->iterable()) for setting linestyles in Collection class. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-09-04 18:29:28 UTC (rev 6063) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-09-04 19:52:42 UTC (rev 6064) @@ -284,7 +284,7 @@ dashes.append(dashd[cbook.ls_mapper[x]]) else: raise ValueError() - elif cbook.iterator(x) and len(x) == 2: + elif cbook.iterable(x) and len(x) == 2: dashes.append(x) else: raise ValueError() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-12-15 06:26:29
|
Revision: 6607 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6607&view=rev Author: efiring Date: 2008-12-15 06:26:18 +0000 (Mon, 15 Dec 2008) Log Message: ----------- In collections, keep track of whether edges or faces are colormapped. Thanks to Eric Bruning for finding the problem and outlining the solution. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-12-15 06:23:25 UTC (rev 6606) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-12-15 06:26:18 UTC (rev 6607) @@ -231,7 +231,7 @@ def get_pickradius(self): return self.pickradius def set_urls(self, urls): - if urls is None: + if urls is None: self._urls = [None,] else: self._urls = urls @@ -365,11 +365,19 @@ """ Set the facecolor(s) of the collection. *c* can be a matplotlib color arg (all patches have same color), or a - sequence or rgba tuples; if it is a sequence the patches will - cycle through the sequence + sequence of rgba tuples; if it is a sequence the patches will + cycle through the sequence. + If *c* is 'none', the patch will not be filled. + ACCEPTS: matplotlib color arg or sequence of rgba tuples """ + self._is_filled = True + try: + if c.lower() == 'none': + self._is_filled = False + except AttributeError: + pass if c is None: c = mpl.rcParams['patch.facecolor'] self._facecolors_original = c self._facecolors = _colors.colorConverter.to_rgba_array(c, self._alpha) @@ -393,14 +401,21 @@ """ Set the edgecolor(s) of the collection. *c* can be a matplotlib color arg (all patches have same color), or a - sequence or rgba tuples; if it is a sequence the patches will + sequence of rgba tuples; if it is a sequence the patches will cycle through the sequence. If *c* is 'face', the edge color will always be the same as - the face color. + the face color. If it is 'none', the patch boundary will not + be drawn. ACCEPTS: matplotlib color arg or sequence of rgba tuples """ + self._is_stroked = True + try: + if c.lower() == 'none': + self._is_stroked = False + except AttributeError: + pass if c == 'face': self._edgecolors = 'face' self._edgecolors_original = 'face' @@ -409,6 +424,7 @@ self._edgecolors_original = c self._edgecolors = _colors.colorConverter.to_rgba_array(c, self._alpha) + def set_edgecolors(self, c): """alias for set_edgecolor""" return self.set_edgecolor(c) @@ -452,9 +468,9 @@ if self._A is None: return if self._A.ndim > 1: raise ValueError('Collections can only map rank 1 arrays') - if len(self._facecolors): + if self._is_filled: self._facecolors = self.to_rgba(self._A, self._alpha) - else: + elif self._is_stroked: self._edgecolors = self.to_rgba(self._A, self._alpha) def update_from(self, other): @@ -887,6 +903,7 @@ Collection.__init__( self, edgecolors=colors, + facecolors='none', linewidths=linewidths, linestyles=linestyles, antialiaseds=antialiaseds, @@ -897,7 +914,6 @@ pickradius=pickradius, **kwargs) - self.set_facecolors([]) self.set_segments(segments) def get_paths(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mme...@us...> - 2009-01-08 19:55:13
|
Revision: 6768 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6768&view=rev Author: mmetz_bn Date: 2009-01-08 19:55:06 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Handle ValueError is val is a string Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-01-08 19:44:07 UTC (rev 6767) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-01-08 19:55:06 UTC (rev 6768) @@ -111,6 +111,7 @@ if cbook.iterable(val) and len(val): try: float(val[0]) except TypeError: pass # raise below + except ValueError: pass else: return val raise TypeError('val must be a float or nonzero sequence of floats') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-08-04 06:52:32
|
Revision: 7340 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7340&view=rev Author: efiring Date: 2009-08-04 06:52:24 +0000 (Tue, 04 Aug 2009) Log Message: ----------- Add PathCollection; reorganize collections.py PathCollection is added to support complex paths in contourf. Other changes are to improve readability and reduce redundancy. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-08-03 20:06:02 UTC (rev 7339) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-08-04 06:52:24 UTC (rev 7340) @@ -5,15 +5,15 @@ The classes are not meant to be as flexible as their single element counterparts (e.g. you may not be able to select all line styles) but -they are meant to be fast for common use cases (e.g. a bunch of solid +they are meant to be fast for common use cases (e.g. a large set of solid line segemnts) """ -import copy, math, warnings +import warnings import numpy as np -from numpy import ma +import numpy.ma as ma import matplotlib as mpl import matplotlib.cbook as cbook -import matplotlib.colors as _colors # avoid conflict with kwarg +import matplotlib.colors as mcolors import matplotlib.cm as cm import matplotlib.transforms as transforms import matplotlib.artist as artist @@ -106,6 +106,7 @@ self._pickradius = pickradius self.update(kwargs) + self._paths = None def _get_value(self, val): @@ -131,6 +132,9 @@ def get_paths(self): + return self._paths + + def set_paths(self): raise NotImplementedError def get_transforms(self): @@ -385,7 +389,7 @@ pass if c is None: c = mpl.rcParams['patch.facecolor'] self._facecolors_original = c - self._facecolors = _colors.colorConverter.to_rgba_array(c, self._alpha) + self._facecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha) def set_facecolors(self, c): """alias for set_facecolor""" @@ -427,7 +431,7 @@ else: if c is None: c = mpl.rcParams['patch.edgecolor'] self._edgecolors_original = c - self._edgecolors = _colors.colorConverter.to_rgba_array(c, self._alpha) + self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha) def set_edgecolors(self, c): @@ -446,13 +450,13 @@ else: artist.Artist.set_alpha(self, alpha) try: - self._facecolors = _colors.colorConverter.to_rgba_array( + self._facecolors = mcolors.colorConverter.to_rgba_array( self._facecolors_original, self._alpha) except (AttributeError, TypeError, IndexError): pass try: if self._edgecolors_original != 'face': - self._edgecolors = _colors.colorConverter.to_rgba_array( + self._edgecolors = mcolors.colorConverter.to_rgba_array( self._edgecolors_original, self._alpha) except (AttributeError, TypeError, IndexError): pass @@ -516,133 +520,27 @@ setting, in sequence form. """ -class QuadMesh(Collection): +class PathCollection(Collection): """ - Class for the efficient drawing of a quadrilateral mesh. - - A quadrilateral mesh consists of a grid of vertices. The - dimensions of this array are (*meshWidth* + 1, *meshHeight* + - 1). Each vertex in the mesh has a different set of "mesh - coordinates" representing its position in the topology of the - mesh. For any values (*m*, *n*) such that 0 <= *m* <= *meshWidth* - and 0 <= *n* <= *meshHeight*, the vertices at mesh coordinates - (*m*, *n*), (*m*, *n* + 1), (*m* + 1, *n* + 1), and (*m* + 1, *n*) - form one of the quadrilaterals in the mesh. There are thus - (*meshWidth* * *meshHeight*) quadrilaterals in the mesh. The mesh - need not be regular and the polygons need not be convex. - - A quadrilateral mesh is represented by a (2 x ((*meshWidth* + 1) * - (*meshHeight* + 1))) numpy array *coordinates*, where each row is - the *x* and *y* coordinates of one of the vertices. To define the - function that maps from a data point to its corresponding color, - use the :meth:`set_cmap` method. Each of these arrays is indexed in - row-major order by the mesh coordinates of the vertex (or the mesh - coordinates of the lower left vertex, in the case of the - colors). - - For example, the first entry in *coordinates* is the - coordinates of the vertex at mesh coordinates (0, 0), then the one - at (0, 1), then at (0, 2) .. (0, meshWidth), (1, 0), (1, 1), and - so on. + This is the most basic :class:`Collection` subclass. """ - def __init__(self, meshWidth, meshHeight, coordinates, showedges, antialiased=True): - Collection.__init__(self) - self._meshWidth = meshWidth - self._meshHeight = meshHeight - self._coordinates = coordinates - self._showedges = showedges - self._antialiased = antialiased - - self._paths = None - - self._bbox = transforms.Bbox.unit() - self._bbox.update_from_data_xy(coordinates.reshape( - ((meshWidth + 1) * (meshHeight + 1), 2))) - - # By converting to floats now, we can avoid that on every draw. - self._coordinates = self._coordinates.reshape((meshHeight + 1, meshWidth + 1, 2)) - self._coordinates = np.array(self._coordinates, np.float_) - - def get_paths(self, dataTrans=None): - if self._paths is None: - self._paths = self.convert_mesh_to_paths( - self._meshWidth, self._meshHeight, self._coordinates) - return self._paths - - @staticmethod - def convert_mesh_to_paths(meshWidth, meshHeight, coordinates): + def __init__(self, paths, **kwargs): """ - Converts a given mesh into a sequence of - :class:`matplotlib.path.Path` objects for easier rendering by - backends that do not directly support quadmeshes. + *paths* is a sequence of :class:`matplotlib.path.Path` + instances. - This function is primarily of use to backend implementers. + %(Collection)s """ - Path = mpath.Path - if ma.isMaskedArray(coordinates): - c = coordinates.data - else: - c = coordinates + Collection.__init__(self, **kwargs) + self.set_paths(paths) + __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd - points = np.concatenate(( - c[0:-1, 0:-1], - c[0:-1, 1: ], - c[1: , 1: ], - c[1: , 0:-1], - c[0:-1, 0:-1] - ), axis=2) - points = points.reshape((meshWidth * meshHeight, 5, 2)) - return [Path(x) for x in points] - def get_datalim(self, transData): - return self._bbox + def set_paths(self, paths): + self._paths = paths - @allow_rasterization - def draw(self, renderer): - if not self.get_visible(): return - renderer.open_group(self.__class__.__name__) - transform = self.get_transform() - transOffset = self._transOffset - offsets = self._offsets - if self.have_units(): - if len(self._offsets): - xs = self.convert_xunits(self._offsets[:0]) - ys = self.convert_yunits(self._offsets[:1]) - offsets = zip(xs, ys) - - offsets = np.asarray(offsets, np.float_) - - if self.check_update('array'): - self.update_scalarmappable() - - clippath, clippath_trans = self.get_transformed_clip_path_and_affine() - if clippath_trans is not None: - clippath_trans = clippath_trans.frozen() - - if not transform.is_affine: - coordinates = self._coordinates.reshape( - (self._coordinates.shape[0] * - self._coordinates.shape[1], - 2)) - coordinates = transform.transform(coordinates) - coordinates = coordinates.reshape(self._coordinates.shape) - transform = transforms.IdentityTransform() - else: - coordinates = self._coordinates - - if not transOffset.is_affine: - offsets = transOffset.transform_non_affine(offsets) - transOffset = transOffset.get_affine() - - renderer.draw_quad_mesh( - transform.frozen(), self.clipbox, clippath, clippath_trans, - self._meshWidth, self._meshHeight, coordinates, - offsets, transOffset, self.get_facecolor(), self._antialiased, - self._showedges) - renderer.close_group(self.__class__.__name__) - class PolyCollection(Collection): def __init__(self, verts, sizes = None, closed = True, **kwargs): """ @@ -687,8 +585,7 @@ else: self._paths = [mpath.Path(xy) for xy in verts] - def get_paths(self): - return self._paths + set_paths = set_verts def draw(self, renderer): if self._sizes is not None: @@ -797,9 +694,6 @@ for x in self._sizes] return Collection.draw(self, renderer) - def get_paths(self): - return self._paths - def get_numsides(self): return self._numsides @@ -907,7 +801,7 @@ if antialiaseds is None: antialiaseds = (mpl.rcParams['lines.antialiased'],) self.set_linestyles(linestyles) - colors = _colors.colorConverter.to_rgba_array(colors) + colors = mcolors.colorConverter.to_rgba_array(colors) Collection.__init__( self, @@ -925,9 +819,6 @@ self.set_segments(segments) - def get_paths(self): - return self._paths - def set_segments(self, segments): if segments is None: return _segments = [] @@ -940,6 +831,7 @@ self._paths = [mpath.Path(seg) for seg in _segments] set_verts = set_segments # for compatibility with PolyCollection + set_paths = set_segments def _add_offsets(self, segs): offsets = self._uniform_offsets @@ -963,7 +855,7 @@ ACCEPTS: matplotlib color arg or sequence of rgba tuples """ - self._edgecolors = _colors.colorConverter.to_rgba_array(c) + self._edgecolors = mcolors.colorConverter.to_rgba_array(c) def color(self, c): """ @@ -1011,8 +903,6 @@ for x in self._sizes] return Collection.draw(self, renderer) - def get_paths(self): - return self._paths class EllipseCollection(Collection): """ @@ -1095,9 +985,6 @@ self.set_transforms() return Collection.draw(self, renderer) - def get_paths(self): - return self._paths - class PatchCollection(Collection): """ A generic collection of patches. @@ -1152,17 +1039,148 @@ else: Collection.__init__(self, **kwargs) - paths = [p.get_transform().transform_path(p.get_path()) + self.set_paths(patches) + + def set_paths(self, patches): + paths = [p.get_transform().transform_path(p.get_path()) for p in patches] - self._paths = paths + +class QuadMesh(Collection): + """ + Class for the efficient drawing of a quadrilateral mesh. + + A quadrilateral mesh consists of a grid of vertices. The + dimensions of this array are (*meshWidth* + 1, *meshHeight* + + 1). Each vertex in the mesh has a different set of "mesh + coordinates" representing its position in the topology of the + mesh. For any values (*m*, *n*) such that 0 <= *m* <= *meshWidth* + and 0 <= *n* <= *meshHeight*, the vertices at mesh coordinates + (*m*, *n*), (*m*, *n* + 1), (*m* + 1, *n* + 1), and (*m* + 1, *n*) + form one of the quadrilaterals in the mesh. There are thus + (*meshWidth* * *meshHeight*) quadrilaterals in the mesh. The mesh + need not be regular and the polygons need not be convex. + + A quadrilateral mesh is represented by a (2 x ((*meshWidth* + 1) * + (*meshHeight* + 1))) numpy array *coordinates*, where each row is + the *x* and *y* coordinates of one of the vertices. To define the + function that maps from a data point to its corresponding color, + use the :meth:`set_cmap` method. Each of these arrays is indexed in + row-major order by the mesh coordinates of the vertex (or the mesh + coordinates of the lower left vertex, in the case of the + colors). + + For example, the first entry in *coordinates* is the + coordinates of the vertex at mesh coordinates (0, 0), then the one + at (0, 1), then at (0, 2) .. (0, meshWidth), (1, 0), (1, 1), and + so on. + """ + def __init__(self, meshWidth, meshHeight, coordinates, showedges, antialiased=True): + Collection.__init__(self) + self._meshWidth = meshWidth + self._meshHeight = meshHeight + self._coordinates = coordinates + self._showedges = showedges + self._antialiased = antialiased + + self._bbox = transforms.Bbox.unit() + self._bbox.update_from_data_xy(coordinates.reshape( + ((meshWidth + 1) * (meshHeight + 1), 2))) + + # By converting to floats now, we can avoid that on every draw. + self._coordinates = self._coordinates.reshape((meshHeight + 1, meshWidth + 1, 2)) + self._coordinates = np.array(self._coordinates, np.float_) + def get_paths(self): + if self._paths is None: + self.set_paths() return self._paths + def set_paths(self): + self._paths = self.convert_mesh_to_paths( + self._meshWidth, self._meshHeight, self._coordinates) + @staticmethod + def convert_mesh_to_paths(meshWidth, meshHeight, coordinates): + """ + Converts a given mesh into a sequence of + :class:`matplotlib.path.Path` objects for easier rendering by + backends that do not directly support quadmeshes. + + This function is primarily of use to backend implementers. + """ + Path = mpath.Path + + if ma.isMaskedArray(coordinates): + c = coordinates.data + else: + c = coordinates + + points = np.concatenate(( + c[0:-1, 0:-1], + c[0:-1, 1: ], + c[1: , 1: ], + c[1: , 0:-1], + c[0:-1, 0:-1] + ), axis=2) + points = points.reshape((meshWidth * meshHeight, 5, 2)) + return [Path(x) for x in points] + + def get_datalim(self, transData): + return self._bbox + + @allow_rasterization + def draw(self, renderer): + if not self.get_visible(): return + renderer.open_group(self.__class__.__name__) + transform = self.get_transform() + transOffset = self._transOffset + offsets = self._offsets + + if self.have_units(): + if len(self._offsets): + xs = self.convert_xunits(self._offsets[:0]) + ys = self.convert_yunits(self._offsets[:1]) + offsets = zip(xs, ys) + + offsets = np.asarray(offsets, np.float_) + + if self.check_update('array'): + self.update_scalarmappable() + + clippath, clippath_trans = self.get_transformed_clip_path_and_affine() + if clippath_trans is not None: + clippath_trans = clippath_trans.frozen() + + if not transform.is_affine: + coordinates = self._coordinates.reshape( + (self._coordinates.shape[0] * + self._coordinates.shape[1], + 2)) + coordinates = transform.transform(coordinates) + coordinates = coordinates.reshape(self._coordinates.shape) + transform = transforms.IdentityTransform() + else: + coordinates = self._coordinates + + if not transOffset.is_affine: + offsets = transOffset.transform_non_affine(offsets) + transOffset = transOffset.get_affine() + + renderer.draw_quad_mesh( + transform.frozen(), self.clipbox, clippath, clippath_trans, + self._meshWidth, self._meshHeight, coordinates, + offsets, transOffset, self.get_facecolor(), self._antialiased, + self._showedges) + renderer.close_group(self.__class__.__name__) + + + + artist.kwdocd['Collection'] = patchstr = artist.kwdoc(Collection) -for k in ('QuadMesh', 'PolyCollection', 'BrokenBarHCollection', 'RegularPolyCollection', +for k in ('QuadMesh', 'PolyCollection', 'BrokenBarHCollection', + 'RegularPolyCollection', 'PathCollection', 'StarPolygonCollection', 'PatchCollection', 'CircleCollection'): artist.kwdocd[k] = patchstr artist.kwdocd['LineCollection'] = artist.kwdoc(LineCollection) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2009-08-18 22:13:18
|
Revision: 7504 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7504&view=rev Author: mdboom Date: 2009-08-18 22:13:11 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Fix clipping on collections. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-08-18 21:59:07 UTC (rev 7503) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-08-18 22:13:11 UTC (rev 7504) @@ -208,8 +208,7 @@ transform, transOffset, offsets, paths = self._prepare_points() gc = renderer.new_gc() - gc.set_clip_rectangle(self.get_clip_box()) - gc.set_clip_path(self.get_clip_path()) + self._set_gc_clip(gc) renderer.draw_path_collection( gc, transform.frozen(), paths, self.get_transforms(), @@ -1210,8 +1209,7 @@ transOffset = transOffset.get_affine() gc = renderer.new_gc() - gc.set_clip_rectangle(self.get_clip_box()) - gc.set_clip_path(self.get_clip_path()) + self._set_clip_gc(gc) if self._shading == 'gouraud': triangles, colors = self.convert_mesh_to_triangles( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2009-08-22 20:16:22
|
Revision: 7520 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7520&view=rev Author: ryanmay Date: 2009-08-22 20:16:09 +0000 (Sat, 22 Aug 2009) Log Message: ----------- Fix typo in QuadMesh. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-08-22 06:25:07 UTC (rev 7519) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-08-22 20:16:09 UTC (rev 7520) @@ -1209,7 +1209,7 @@ transOffset = transOffset.get_affine() gc = renderer.new_gc() - self._set_clip_gc(gc) + self._set_gc_clip(gc) if self._shading == 'gouraud': triangles, colors = self.convert_mesh_to_triangles( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2009-09-03 14:36:46
|
Revision: 7631 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7631&view=rev Author: mdboom Date: 2009-09-03 14:36:37 +0000 (Thu, 03 Sep 2009) Log Message: ----------- Remove unnecessary line. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-09-02 20:48:06 UTC (rev 7630) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-09-03 14:36:37 UTC (rev 7631) @@ -1218,7 +1218,6 @@ if self._shading == 'gouraud': triangles, colors = self.convert_mesh_to_triangles( self._meshWidth, self._meshHeight, coordinates) - check = {} renderer.draw_gouraud_triangles(gc, triangles, colors, transform.frozen()) else: renderer.draw_quad_mesh( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-11-01 04:38:06
|
Revision: 7912 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7912&view=rev Author: leejjoon Date: 2009-11-01 04:37:56 +0000 (Sun, 01 Nov 2009) Log Message: ----------- Fix LineCollection not setting color correctly Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-10-29 19:04:42 UTC (rev 7911) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-11-01 04:37:56 UTC (rev 7912) @@ -856,7 +856,7 @@ ACCEPTS: matplotlib color arg or sequence of rgba tuples """ - self._edgecolors = mcolors.colorConverter.to_rgba_array(c) + self.set_edgecolor(c) def color(self, c): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-05-24 20:06:26
|
Revision: 8335 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8335&view=rev Author: efiring Date: 2010-05-24 20:06:20 +0000 (Mon, 24 May 2010) Log Message: ----------- collections: fix bug in handling of antialiased kwarg Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2010-05-24 13:27:58 UTC (rev 8334) +++ trunk/matplotlib/lib/matplotlib/collections.py 2010-05-24 20:06:20 UTC (rev 8335) @@ -109,29 +109,31 @@ self.update(kwargs) self._paths = None - - def _get_value(self, val): - try: return (float(val), ) + @staticmethod + def _get_value(val): + try: + return (float(val), ) except TypeError: if cbook.iterable(val) and len(val): - try: float(val[0]) - except TypeError: pass # raise below - except ValueError: pass - else: return val + try: + float(val[0]) + except (TypeError, ValueError): + pass # raise below + else: + return val raise TypeError('val must be a float or nonzero sequence of floats') - def _get_bool(self, val): - try: return (bool(val), ) - except TypeError: - if cbook.iterable(val) and len(val): - try: bool(val[0]) - except TypeError: pass # raise below - else: return val + @staticmethod + def _get_bool(val): + if not cbook.iterable(val): + val = (val,) + try: + bool(val[0]) + except (TypeError, IndexError): + raise TypeError('val must be a bool or nonzero sequence of them') + return val - raise TypeError('val must be a bool or nonzero sequence of them') - - def get_paths(self): return self._paths This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-05 04:19:16
|
Revision: 8381 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8381&view=rev Author: efiring Date: 2010-06-05 04:19:10 +0000 (Sat, 05 Jun 2010) Log Message: ----------- collections: add @allow_rasterization to draw methods. Draw methods need the decorator even if they call a decorated draw method, because the decorator flags the method with the _supports_rasterization attribute. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2010-06-04 22:06:07 UTC (rev 8380) +++ trunk/matplotlib/lib/matplotlib/collections.py 2010-06-05 04:19:10 UTC (rev 8381) @@ -596,6 +596,7 @@ set_paths = set_verts + @allow_rasterization def draw(self, renderer): if self._sizes is not None: self._transforms = [ @@ -904,6 +905,7 @@ "return sizes of circles" return self._sizes + @allow_rasterization def draw(self, renderer): # sizes is the area of the circle circumscribing the polygon # in points^2 @@ -991,7 +993,7 @@ m[:2, 2:] = 0 self.set_transform(_affine(m)) - + @allow_rasterization def draw(self, renderer): self._set_transforms() Collection.draw(self, renderer) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2011-02-06 02:41:28
|
Revision: 8950 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8950&view=rev Author: efiring Date: 2011-02-06 02:41:22 +0000 (Sun, 06 Feb 2011) Log Message: ----------- collections with color mapping: don't update rgba unnecesarily Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2011-02-06 01:55:50 UTC (rev 8949) +++ trunk/matplotlib/lib/matplotlib/collections.py 2011-02-06 02:41:22 UTC (rev 8950) @@ -479,9 +479,12 @@ If the scalar mappable array is not none, update colors from scalar data """ - if self._A is None: return + if self._A is None: + return if self._A.ndim > 1: raise ValueError('Collections can only map rank 1 arrays') + if not self.check_update("array"): + return if self._is_filled: self._facecolors = self.to_rgba(self._A, self._alpha) elif self._is_stroked: @@ -807,7 +810,7 @@ The default is 5 pt. The use of :class:`~matplotlib.cm.ScalarMappable` is optional. - If the :class:`~matplotlib.cm.ScalarMappable` matrix + If the :class:`~matplotlib.cm.ScalarMappable` array :attr:`~matplotlib.cm.ScalarMappable._A` is not None (ie a call to :meth:`~matplotlib.cm.ScalarMappable.set_array` has been made), at draw time a call to scalar mappable will be made to set the colors. @@ -1215,8 +1218,7 @@ offsets = np.asarray(offsets, np.float_) - if self.check_update('array'): - self.update_scalarmappable() + self.update_scalarmappable() if not transform.is_affine: coordinates = self._coordinates.reshape( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2011-02-06 05:06:53
|
Revision: 8951 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8951&view=rev Author: efiring Date: 2011-02-06 05:06:46 +0000 (Sun, 06 Feb 2011) Log Message: ----------- bugfix: Collection.set_edgecolor was failing in mplot3d/contour_demo2 Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2011-02-06 02:41:22 UTC (rev 8950) +++ trunk/matplotlib/lib/matplotlib/collections.py 2011-02-06 05:06:46 UTC (rev 8951) @@ -428,13 +428,17 @@ self._is_stroked = False except AttributeError: pass - if c == 'face': - self._edgecolors = 'face' - self._edgecolors_original = 'face' - else: - if c is None: c = mpl.rcParams['patch.edgecolor'] - self._edgecolors_original = c - self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha) + try: + if c.lower() == 'face': + self._edgecolors = 'face' + self._edgecolors_original = 'face' + return + except AttributeError: + pass + if c is None: + c = mpl.rcParams['patch.edgecolor'] + self._edgecolors_original = c + self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha) def set_edgecolors(self, c): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |