Skip to content

Fixed show_edges and renamed dist_func to color_func #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions plotly/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,8 +1517,8 @@ def _map_z2color(zvals, colormap, vmin, vmax):
return labelled_colors

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

if not dist_func:
if not color_func:
# mean values of z-coordinates of triangle vertices
mean_dists = tri_vertices[:, :, 2].mean(-1)
else:
Expand All @@ -1544,17 +1544,19 @@ def _trisurf(x, y, z, simplices, colormap=None, dist_func=None,
for triangle in tri_vertices:
dists = []
for vertex in triangle:
dist = dist_func(vertex[0], vertex[1], vertex[2])
dist = color_func(vertex[0], vertex[1], vertex[2])
dists.append(dist)

mean_dists.append(np.mean(dists))

min_mean_dists = np.min(mean_dists)
max_mean_dists = np.max(mean_dists)
facecolor = FigureFactory._map_z2color(mean_dists, colormap,
min_mean_dists, max_mean_dists)
ii, jj, kk = zip(*simplices)
facecolor = FigureFactory._map_z2color(mean_dists,
colormap,
min_mean_dists,
max_mean_dists)

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

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

@staticmethod
def create_trisurf(x, y, z, simplices, colormap=None,
dist_func=None, title='Trisurf Plot',
def create_trisurf(x, y, z, simplices, colormap=None, color_func=None,
title='Trisurf Plot', plot_edges=True,
showbackground=True,
backgroundcolor='rgb(230, 230, 230)',
gridcolor='rgb(255, 255, 255)',
Expand All @@ -1624,12 +1626,13 @@ def create_trisurf(x, y, z, simplices, colormap=None,
containing 2 triplets. These triplets must be of the form (a,b,c)
or 'rgb(x,y,z)' where a,b,c belong to the interval [0,1] and x,y,z
belong to [0,255]
:param (function) dist_func: The function that determines how the
coloring of the surface changes. It takes 3 arguments x, y, z and
must return a formula of these variables which can include numpy
functions (eg. np.sqrt). If set to None, color will only depend on
the z axis.
:param (function|list) color_func: The parameter that determines the
coloring of the surface. Takes either a function with 3 arguments
x, y, z or a list/array of color values the same length as
simplices. If set to None, color will only depend on the z axis.
:param (str) title: title of the plot
:param (bool) plot_edges: determines if the triangles on the trisurf
are visible
:param (bool) showbackground: makes background in plot visible
:param (str) backgroundcolor: color of background. Takes a string of
the form 'rgb(x,y,z)' x,y,z are between 0 and 255 inclusive.
Expand Down Expand Up @@ -1776,7 +1779,7 @@ def dist_origin(x, y, z):
fig1 = FF.create_trisurf(x=x, y=y, z=z,
colormap="Blues",
simplices=simplices,
dist_func=dist_origin)
color_func=dist_origin)
# Plot the data
py.iplot(fig1, filename='Trisurf Plot - Custom Coloring')
```
Expand Down Expand Up @@ -1851,9 +1854,9 @@ def dist_origin(x, y, z):
"exceed 1.0.")

data1 = FigureFactory._trisurf(x, y, z, simplices,
dist_func=dist_func,
color_func=color_func,
colormap=colormap,
plot_edges=True)
plot_edges=plot_edges)
axis = dict(
showbackground=showbackground,
backgroundcolor=backgroundcolor,
Expand Down