@@ -33,8 +33,8 @@ def tripcolor(ax, *args, **kwargs):
33
33
points, or one per triangle in the triangulation if color values
34
34
are defined at triangles. If there are the same number of points
35
35
and triangles in the triangulation it is assumed that color
36
- values are defined at points unless the kwarg *colorpoints* is
37
- set to *False *.
36
+ values are defined at points; to force the use of color values at
37
+ triangles use the kwarg *facecolors*=C instead of just *C *.
38
38
39
39
*shading* may be 'flat' (the default) or 'gouraud'. If *shading*
40
40
is 'flat' and C values are defined at points, the color values
@@ -58,10 +58,32 @@ def tripcolor(ax, *args, **kwargs):
58
58
vmin = kwargs .pop ('vmin' , None )
59
59
vmax = kwargs .pop ('vmax' , None )
60
60
shading = kwargs .pop ('shading' , 'flat' )
61
- colorpoints = kwargs .pop ('colorpoints ' , True )
61
+ facecolors = kwargs .pop ('facecolors ' , None )
62
62
63
63
tri , args , kwargs = Triangulation .get_from_args_and_kwargs (* args , ** kwargs )
64
- C = np .asarray (args [0 ])
64
+
65
+ # C is the colors array, defined at either points or faces (i.e. triangles).
66
+ # If facecolors is None, C are defined at points.
67
+ # If facecolors is not None, C are defined at faces.
68
+ if facecolors is not None :
69
+ C = facecolors
70
+ else :
71
+ C = np .asarray (args [0 ])
72
+
73
+ # If there are a different number of points and triangles in the
74
+ # triangulation, can omit facecolors kwarg as it is obvious from
75
+ # length of C whether it refers to points or faces.
76
+ # Do not do this for gouraud shading.
77
+ if facecolors is None and len (C ) == len (tri .triangles ) and \
78
+ len (C ) != len (tri .x ) and shading != 'gouraud' :
79
+ facecolors = C
80
+
81
+ # Check length of C is OK.
82
+ if (facecolors is None and len (C ) != len (tri .x )) or \
83
+ (facecolors is not None and len (C ) != len (tri .triangles )):
84
+ raise ValueError ('Length of color values array must be the same '
85
+ 'as either the number of triangulation points '
86
+ 'or triangles' )
65
87
66
88
67
89
# Handling of linewidths, shading, edgecolors and antialiased as
@@ -86,29 +108,22 @@ def tripcolor(ax, *args, **kwargs):
86
108
87
109
88
110
if shading == 'gouraud' :
111
+ if facecolors is not None :
112
+ raise ValueError ('Gouraud shading does not support the use '
113
+ 'of facecolors kwarg' )
89
114
if len (C ) != len (tri .x ):
90
- raise ValueError ('For gouraud shading, the length of C '
91
- 'array must be the same as the number of '
92
- 'triangulation points' )
115
+ raise ValueError ('For gouraud shading, the length of color '
116
+ 'values array must be the same as the '
117
+ 'number of triangulation points' )
93
118
collection = TriMesh (tri , ** kwargs )
94
119
else :
95
- if len (C ) != len (tri .x ) and len (C ) != len (tri .triangles ):
96
- raise ValueError ('Length of C array must be the same as either '
97
- 'the number of triangulation points or triangles' )
98
-
99
- # CAtPoints is True if C defined at points
100
- # or False if C defined at triangles.
101
- CAtPoints = (len (C ) == len (tri .x ))
102
- if len (C ) == len (tri .x ) and len (C ) == len (tri .triangles ):
103
- CAtPoints = colorpoints
104
-
105
120
# Vertices of triangles.
106
121
maskedTris = tri .get_masked_triangles ()
107
122
verts = np .concatenate ((tri .x [maskedTris ][...,np .newaxis ],
108
123
tri .y [maskedTris ][...,np .newaxis ]), axis = 2 )
109
124
110
125
# Color values.
111
- if CAtPoints :
126
+ if facecolors is None :
112
127
# One color per triangle, the mean of the 3 vertex color values.
113
128
C = C [maskedTris ].mean (axis = 1 )
114
129
elif tri .mask is not None :
0 commit comments