From: <mme...@us...> - 2008-04-02 13:34:01
|
Revision: 5027 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5027&view=rev Author: mmetz_bn Date: 2008-04-02 06:33:21 -0700 (Wed, 02 Apr 2008) Log Message: ----------- added linestyle patch Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/cbook.py trunk/matplotlib/lib/matplotlib/collections.py trunk/matplotlib/lib/matplotlib/lines.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-03-27 14:42:26 UTC (rev 5026) +++ trunk/matplotlib/CHANGELOG 2008-04-02 13:33:21 UTC (rev 5027) @@ -1,3 +1,6 @@ +2008-04-02 Allow to use both linestyle definition arguments, '-' and + 'solid' etc. in plots/collections - MM + 2008-03-27 Fix saving to Unicode filenames with Agg backend (other backends appear to already work...) (Thanks, Christopher Barker) - MGD Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2008-03-27 14:42:26 UTC (rev 5026) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-04-02 13:33:21 UTC (rev 5027) @@ -1068,6 +1068,16 @@ return result + +# a dict to cross-map linestyle arguments +_linestyles = [('-', 'solid'), + ('--', 'dashed'), + ('-.', 'dashdot'), + (':', 'dotted')] + +ls_mapper = dict(_linestyles) +ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles]) + if __name__=='__main__': assert( allequal([1,1,1]) ) assert(not allequal([1,1,0]) ) Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-03-27 14:42:26 UTC (rev 5026) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-04-02 13:33:21 UTC (rev 5027) @@ -228,14 +228,25 @@ ACCEPTS: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) ] """ try: + dashd = backend_bases.GraphicsContextBase.dashd if cbook.is_string_like(ls): - dashes = [backend_bases.GraphicsContextBase.dashd[ls]] + if dashd.has_key(ls): + dashes = [dashd[ls]] + elif cbook.ls_mapper.has_key(ls): + dashes = [dashd[cbook.ls_mapper[ls]]] + else: + raise ValueError() elif cbook.iterable(ls): try: dashes = [] for x in ls: if cbook.is_string_like(x): - dashes.append(backend_bases.GraphicsContextBase.dashd[ls]) + if dashd.has_key(x): + dashes.append(dashd[x]) + elif cbook.ls_mapper.has_key(x): + dashes.append(dashd[cbook.ls_mapper[x]]) + else: + raise ValueError() elif cbook.iterator(x) and len(x) == 2: dashes.append(x) else: Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2008-03-27 14:42:26 UTC (rev 5026) +++ trunk/matplotlib/lib/matplotlib/lines.py 2008-04-02 13:33:21 UTC (rev 5027) @@ -11,7 +11,7 @@ from matplotlib import verbose import artist from artist import Artist -from cbook import iterable, is_string_like, is_numlike +from cbook import iterable, is_string_like, is_numlike, ls_mapper from colors import colorConverter from path import Path from transforms import Affine2D, Bbox, TransformedPath @@ -598,7 +598,10 @@ ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post' | 'None' | ' ' | '' ] """ if linestyle not in self._lineStyles: - verbose.report('Unrecognized line style %s, %s' % + if ls_mapper.has_key(linestyle): + linestyle = ls_mapper[linestyle] + else: + verbose.report('Unrecognized line style %s, %s' % (linestyle, type(linestyle))) if linestyle in [' ','']: linestyle = 'None' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |