Skip to content

Commit 99da200

Browse files
committed
adding support for custom colors to trisurf
1 parent e34082a commit 99da200

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

plotly/tools.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,9 +1533,14 @@ def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
15331533
# vertices of the surface triangles
15341534
tri_vertices = points3D[simplices]
15351535

1536-
if not color_func:
1536+
if color_func is None:
15371537
# mean values of z-coordinates of triangle vertices
15381538
mean_dists = tri_vertices[:, :, 2].mean(-1)
1539+
elif isinstance(color_func, (list, np.ndarray)):
1540+
if len(color_func) != len(simplices):
1541+
raise ValueError('If color_func is a list/array, must'
1542+
' be the same length as simplices')
1543+
mean_dists = color_func
15391544
else:
15401545
# apply user inputted function to calculate
15411546
# custom coloring for triangle vertices
@@ -1548,13 +1553,15 @@ def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
15481553
dists.append(dist)
15491554

15501555
mean_dists.append(np.mean(dists))
1551-
1552-
min_mean_dists = np.min(mean_dists)
1553-
max_mean_dists = np.max(mean_dists)
1554-
facecolor = FigureFactory._map_z2color(mean_dists,
1555-
colormap,
1556-
min_mean_dists,
1557-
max_mean_dists)
1556+
if isinstance(mean_dists[0], str):
1557+
facecolor = mean_dists
1558+
else:
1559+
min_mean_dists = np.min(mean_dists)
1560+
max_mean_dists = np.max(mean_dists)
1561+
facecolor = FigureFactory._map_z2color(mean_dists,
1562+
colormap,
1563+
min_mean_dists,
1564+
max_mean_dists)
15581565

15591566
ii, jj, kk = zip(*simplices)
15601567
triangles = graph_objs.Mesh3d(x=x, y=y, z=z, facecolor=facecolor,

0 commit comments

Comments
 (0)