Revision: 8502
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8502&view=rev
Author: ianthomas23
Date: 2010-07-06 08:50:34 +0000 (Tue, 06 Jul 2010)
Log Message:
-----------
Improved triplot performance.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/tri/triplot.py
Modified: trunk/matplotlib/lib/matplotlib/tri/triplot.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/tri/triplot.py 2010-07-06 03:04:59 UTC
(rev 8501)
+++ trunk/matplotlib/lib/matplotlib/tri/triplot.py 2010-07-06 08:50:34 UTC
(rev 8502)
@@ -1,4 +1,9 @@
+import matplotlib.axes
+from matplotlib.cbook import ls_mapper
+from matplotlib.patches import PathPatch
+from matplotlib.path import Path
from matplotlib.tri.triangulation import Triangulation
+import numpy as np
def triplot(ax, *args, **kwargs):
"""
@@ -43,17 +48,30 @@
# If draw both lines and markers at the same time, e.g.
# ax.plot(x[edges].T, y[edges].T, *args, **kwargs)
# then the markers are drawn more than once which is incorrect if alpha<1.
- # Hence draw of lines and markers separately.
+ # Hence draw lines and markers separately.
- # Draw lines without markers.
- marker = kwargs.pop('marker', None)
- kwargs['marker'] = ''
- ax.plot(x[edges].T, y[edges].T, *args, **kwargs)
- if marker is None:
- kwargs.pop('marker')
- else:
- kwargs['marker'] = marker
+ # Decode plot format string, e.g. 'ro-'
+ fmt = ''
+ if len(args) > 0:
+ fmt = args[0]
+ linestyle, marker, color = matplotlib.axes._process_plot_format(fmt)
+ # Draw lines without markers, if lines are required.
+ if linestyle is not None and linestyle is not 'None':
+ kw = kwargs.copy()
+ kw.pop('marker', None) # Ignore marker if set.
+ kw['linestyle'] = ls_mapper[linestyle]
+ kw['edgecolor'] = color
+ kw['facecolor'] = None
+
+ vertices = np.column_stack((x[edges].flatten(), y[edges].flatten()))
+ codes = ([Path.MOVETO] + [Path.LINETO])*len(edges)
+
+ path = Path(vertices, codes)
+ pathpatch = PathPatch(path, **kw)
+
+ ax.add_patch(pathpatch)
+
# Draw markers without lines.
# Should avoid drawing markers for points that are not in any triangle?
kwargs['linestyle'] = ''
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins