|
| 1 | +import matplotlib.axes |
| 2 | +from matplotlib.cbook import ls_mapper |
| 3 | +from matplotlib.patches import PathPatch |
| 4 | +from matplotlib.path import Path |
1 | 5 | from matplotlib.tri.triangulation import Triangulation
|
| 6 | +import numpy as np |
2 | 7 |
|
3 | 8 | def triplot(ax, *args, **kwargs):
|
4 | 9 | """
|
@@ -43,16 +48,29 @@ def triplot(ax, *args, **kwargs):
|
43 | 48 | # If draw both lines and markers at the same time, e.g.
|
44 | 49 | # ax.plot(x[edges].T, y[edges].T, *args, **kwargs)
|
45 | 50 | # 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) |
56 | 74 |
|
57 | 75 | # Draw markers without lines.
|
58 | 76 | # Should avoid drawing markers for points that are not in any triangle?
|
|
0 commit comments