Skip to content

Commit 1935cf1

Browse files
committed
Merge pull request #482 from plotly/trisurf_fixes
Fixed show_edges and renamed dist_func to color_func
2 parents a9384b9 + 78a3b3f commit 1935cf1

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

plotly/tools.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,8 @@ def _map_z2color(zvals, colormap, vmin, vmax):
15171517
return labelled_colors
15181518

15191519
@staticmethod
1520-
def _trisurf(x, y, z, simplices, colormap=None, dist_func=None,
1521-
plot_edges=None, x_edge=None, y_edge=None, z_edge=None):
1520+
def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
1521+
plot_edges=False, x_edge=None, y_edge=None, z_edge=None):
15221522
"""
15231523
Refer to FigureFactory.create_trisurf() for docstring
15241524
"""
@@ -1533,7 +1533,7 @@ def _trisurf(x, y, z, simplices, colormap=None, dist_func=None,
15331533
# vertices of the surface triangles
15341534
tri_vertices = points3D[simplices]
15351535

1536-
if not dist_func:
1536+
if not color_func:
15371537
# mean values of z-coordinates of triangle vertices
15381538
mean_dists = tri_vertices[:, :, 2].mean(-1)
15391539
else:
@@ -1544,17 +1544,19 @@ def _trisurf(x, y, z, simplices, colormap=None, dist_func=None,
15441544
for triangle in tri_vertices:
15451545
dists = []
15461546
for vertex in triangle:
1547-
dist = dist_func(vertex[0], vertex[1], vertex[2])
1547+
dist = color_func(vertex[0], vertex[1], vertex[2])
15481548
dists.append(dist)
15491549

15501550
mean_dists.append(np.mean(dists))
15511551

15521552
min_mean_dists = np.min(mean_dists)
15531553
max_mean_dists = np.max(mean_dists)
1554-
facecolor = FigureFactory._map_z2color(mean_dists, colormap,
1555-
min_mean_dists, max_mean_dists)
1556-
ii, jj, kk = zip(*simplices)
1554+
facecolor = FigureFactory._map_z2color(mean_dists,
1555+
colormap,
1556+
min_mean_dists,
1557+
max_mean_dists)
15571558

1559+
ii, jj, kk = zip(*simplices)
15581560
triangles = graph_objs.Mesh3d(x=x, y=y, z=z, facecolor=facecolor,
15591561
i=ii, j=jj, k=kk, name='')
15601562

@@ -1603,8 +1605,8 @@ def _trisurf(x, y, z, simplices, colormap=None, dist_func=None,
16031605
return graph_objs.Data([triangles, lines])
16041606

16051607
@staticmethod
1606-
def create_trisurf(x, y, z, simplices, colormap=None,
1607-
dist_func=None, title='Trisurf Plot',
1608+
def create_trisurf(x, y, z, simplices, colormap=None, color_func=None,
1609+
title='Trisurf Plot', plot_edges=True,
16081610
showbackground=True,
16091611
backgroundcolor='rgb(230, 230, 230)',
16101612
gridcolor='rgb(255, 255, 255)',
@@ -1624,12 +1626,13 @@ def create_trisurf(x, y, z, simplices, colormap=None,
16241626
containing 2 triplets. These triplets must be of the form (a,b,c)
16251627
or 'rgb(x,y,z)' where a,b,c belong to the interval [0,1] and x,y,z
16261628
belong to [0,255]
1627-
:param (function) dist_func: The function that determines how the
1628-
coloring of the surface changes. It takes 3 arguments x, y, z and
1629-
must return a formula of these variables which can include numpy
1630-
functions (eg. np.sqrt). If set to None, color will only depend on
1631-
the z axis.
1629+
:param (function|list) color_func: The parameter that determines the
1630+
coloring of the surface. Takes either a function with 3 arguments
1631+
x, y, z or a list/array of color values the same length as
1632+
simplices. If set to None, color will only depend on the z axis.
16321633
:param (str) title: title of the plot
1634+
:param (bool) plot_edges: determines if the triangles on the trisurf
1635+
are visible
16331636
:param (bool) showbackground: makes background in plot visible
16341637
:param (str) backgroundcolor: color of background. Takes a string of
16351638
the form 'rgb(x,y,z)' x,y,z are between 0 and 255 inclusive.
@@ -1776,7 +1779,7 @@ def dist_origin(x, y, z):
17761779
fig1 = FF.create_trisurf(x=x, y=y, z=z,
17771780
colormap="Blues",
17781781
simplices=simplices,
1779-
dist_func=dist_origin)
1782+
color_func=dist_origin)
17801783
# Plot the data
17811784
py.iplot(fig1, filename='Trisurf Plot - Custom Coloring')
17821785
```
@@ -1851,9 +1854,9 @@ def dist_origin(x, y, z):
18511854
"exceed 1.0.")
18521855

18531856
data1 = FigureFactory._trisurf(x, y, z, simplices,
1854-
dist_func=dist_func,
1857+
color_func=color_func,
18551858
colormap=colormap,
1856-
plot_edges=True)
1859+
plot_edges=plot_edges)
18571860
axis = dict(
18581861
showbackground=showbackground,
18591862
backgroundcolor=backgroundcolor,

0 commit comments

Comments
 (0)