Skip to content

Commit e21b1ca

Browse files
committed
Improved triplot performance.
svn path=/trunk/matplotlib/; revision=8502
1 parent 97143d0 commit e21b1ca

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

lib/matplotlib/tri/triplot.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import matplotlib.axes
2+
from matplotlib.cbook import ls_mapper
3+
from matplotlib.patches import PathPatch
4+
from matplotlib.path import Path
15
from matplotlib.tri.triangulation import Triangulation
6+
import numpy as np
27

38
def triplot(ax, *args, **kwargs):
49
"""
@@ -43,16 +48,29 @@ def triplot(ax, *args, **kwargs):
4348
# If draw both lines and markers at the same time, e.g.
4449
# ax.plot(x[edges].T, y[edges].T, *args, **kwargs)
4550
# then the markers are drawn more than once which is incorrect if alpha<1.
46-
# Hence draw of lines and markers separately.
47-
48-
# Draw lines without markers.
49-
marker = kwargs.pop('marker', None)
50-
kwargs['marker'] = ''
51-
ax.plot(x[edges].T, y[edges].T, *args, **kwargs)
52-
if marker is None:
53-
kwargs.pop('marker')
54-
else:
55-
kwargs['marker'] = marker
51+
# Hence draw lines and markers separately.
52+
53+
# Decode plot format string, e.g. 'ro-'
54+
fmt = ''
55+
if len(args) > 0:
56+
fmt = args[0]
57+
linestyle, marker, color = matplotlib.axes._process_plot_format(fmt)
58+
59+
# Draw lines without markers, if lines are required.
60+
if linestyle is not None and linestyle is not 'None':
61+
kw = kwargs.copy()
62+
kw.pop('marker', None) # Ignore marker if set.
63+
kw['linestyle'] = ls_mapper[linestyle]
64+
kw['edgecolor'] = color
65+
kw['facecolor'] = None
66+
67+
vertices = np.column_stack((x[edges].flatten(), y[edges].flatten()))
68+
codes = ([Path.MOVETO] + [Path.LINETO])*len(edges)
69+
70+
path = Path(vertices, codes)
71+
pathpatch = PathPatch(path, **kw)
72+
73+
ax.add_patch(pathpatch)
5674

5775
# Draw markers without lines.
5876
# Should avoid drawing markers for points that are not in any triangle?

0 commit comments

Comments
 (0)