Skip to content

added appropriate colorbar max and min values, edges_color to param for line coloring, and making code more clear #551

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 4 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
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
60 changes: 0 additions & 60 deletions plotly/tests/test_optional/temp-plot.html

This file was deleted.

101 changes: 50 additions & 51 deletions plotly/tests/test_optional/test_figure_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,29 +842,28 @@ def test_trisurf_all_args(self):
)

exp_trisurf_plot = {
'data': [{'facecolor': np.array(
['rgb(144, 94, 132)',
'rgb(23, 190, 207)',
'rgb(144, 94, 132)',
'rgb(31, 119, 180)',
'rgb(144, 94, 132)',
'rgb(31, 119, 180)',
'rgb(144, 94, 132)',
'rgb(23, 190, 207)']
),
'i': np.array([3, 1, 1, 5, 7, 3, 5, 7]),
'j': np.array([1, 3, 5, 1, 3, 7, 7, 5]),
'k': np.array([4, 0, 4, 2, 4, 6, 4, 8]),
'name': '',
'type': 'mesh3d',
'x': np.array([-1., 0., 1., -1., 0., 1.,
-1., 0., 1.]),
'y': np.array([-1., -1., -1., 0., 0., 0.,
1., 1., 1.]),
'z': np.array([1., -0., -1., -0., 0., 0.,
-1., 0., 1.])},
'data': [{'facecolor': ['rgb(144, 94, 132)',
'rgb(23, 190, 207)',
'rgb(144, 94, 132)',
'rgb(31, 119, 180)',
'rgb(144, 94, 132)',
'rgb(31, 119, 180)',
'rgb(144, 94, 132)',
'rgb(23, 190, 207)'],
'i': np.array([3, 1, 1, 5, 7, 3, 5, 7]),
'j': np.array([1, 3, 5, 1, 3, 7, 7, 5]),
'k': np.array([4, 0, 4, 2, 4, 6, 4, 8]),
'name': '',
'type': 'mesh3d',
'x': np.array([-1., 0., 1., -1., 0.,
1., -1., 0., 1.]),
'y': np.array([-1., -1., -1., 0., 0.,
0., 1., 1., 1.]),
'z': np.array([1., -0., -1., -0., 0.,
0., -1., 0., 1.])},
{'line': {'color': 'rgb(50, 50, 50)', 'width': 1.5},
'mode': 'lines',
'showlegend': False,
'type': 'scatter3d',
'x': np.array([-1.0, 0.0, 0.0, -1.0, None, 0.0, -1.0,
-1.0, 0.0, None, 0.0, 1.0, 0.0, 0.0,
Expand All @@ -884,43 +883,43 @@ def test_trisurf_all_args(self):
-0.0, 0.0, 0.0, None, -0.0, 0.0, -1.0,
-0.0, None, 0.0, 0.0, 0.0, 0.0, None,
0.0, 0.0, 1.0, 0.0, None])},
{'colorscale': [[0.0, 'rgb(31, 119, 180)'],
[0.1111111111111111, 'rgb(255, 127, 14)'],
[0.2222222222222222, 'rgb(44, 160, 44)'],
[0.3333333333333333, 'rgb(214, 39, 40)'],
[0.4444444444444444, 'rgb(148, 103, 189)'],
[0.5555555555555556, 'rgb(140, 86, 75)'],
[0.6666666666666666, 'rgb(227, 119, 194)'],
[0.7777777777777778, 'rgb(127, 127, 127)'],
[0.8888888888888888, 'rgb(188, 189, 34)'],
[1.0, 'rgb(23, 190, 207)']],
'intensity': [0, 1],
'showscale': True,
'type': 'mesh3d',
'x': [0, 1],
'y': [0, 1],
'z': [0, 1]}],
{'hoverinfo': 'None',
'marker': {'color': [-0.33333333333333331,
0.33333333333333331],
'colorscale': [
[0.0, 'rgb(31, 119, 180)'],
[0.1111111111111111, 'rgb(255, 127, 14)'],
[0.2222222222222222, 'rgb(44, 160, 44)'],
[0.3333333333333333, 'rgb(214, 39, 40)'],
[0.4444444444444444, 'rgb(148, 103, 189)'],
[0.5555555555555556, 'rgb(140, 86, 75)'],
[0.6666666666666666, 'rgb(227, 119, 194)'],
[0.7777777777777778, 'rgb(127, 127, 127)'],
[0.8888888888888888, 'rgb(188, 189, 34)'],
[1.0, 'rgb(23, 190, 207)']
],
'showscale': True,
'size': 0.1},
'mode': 'markers',
'showlegend': False,
'type': 'scatter3d',
'x': -1.0,
'y': -1.0,
'z': 1.0}],
'layout': {'height': 800,
'scene': {'aspectratio': {'x': 1, 'y': 1, 'z': 1},
'xaxis': {'backgroundcolor':
'rgb(230, 230, 230)',
'gridcolor':
'rgb(255, 255, 255)',
'xaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
'gridcolor': 'rgb(255, 255, 255)',
'showbackground': True,
'zerolinecolor':
'rgb(255, 255, 255)'},
'yaxis': {'backgroundcolor':
'rgb(230, 230, 230)',
'zerolinecolor': 'rgb(255, 255, 255)'},
'yaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
'gridcolor': 'rgb(255, 255, 255)',
'showbackground': True,
'zerolinecolor':
'rgb(255, 255, 255)'},
'zaxis': {'backgroundcolor':
'rgb(230, 230, 230)',
'zerolinecolor': 'rgb(255, 255, 255)'},
'zaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
'gridcolor': 'rgb(255, 255, 255)',
'showbackground': True,
'zerolinecolor':
'rgb(255, 255, 255)'}},
'zerolinecolor': 'rgb(255, 255, 255)'}},
'title': 'Trisurf Plot',
'width': 800}
}
Expand Down
77 changes: 50 additions & 27 deletions plotly/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3269,9 +3269,9 @@ def _map_face2color(face, colormap, vmin, vmax):
return face_color

@staticmethod
def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
color_func=None, plot_edges=False, x_edge=None, y_edge=None,
z_edge=None, facecolor=None):
def _trisurf(x, y, z, simplices, show_colorbar, edges_color,
colormap=None, color_func=None, plot_edges=False,
x_edge=None, y_edge=None, z_edge=None, facecolor=None):
"""
Refer to FigureFactory.create_trisurf() for docstring
"""
Expand All @@ -3297,13 +3297,17 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
raise ValueError("If color_func is a list/array, it must "
"be the same length as simplices.")

# convert all colors to rgb
# convert all colors in color_func to rgb
for index in range(len(color_func)):
if isinstance(color_func[index], str):
if '#' in color_func[index]:
foo = FigureFactory._hex_to_rgb(color_func[index])
color_func[index] = FigureFactory._label_rgb(foo)

if isinstance(color_func[index], tuple):
foo = FigureFactory._convert_to_RGB_255(color_func[index])
color_func[index] = FigureFactory._label_rgb(foo)

mean_dists = np.asarray(color_func)
else:
# apply user inputted function to calculate
Expand Down Expand Up @@ -3333,30 +3337,41 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
max_mean_dists)
facecolor.append(color)

# Make sure we have arrays to speed up plotting
# Make sure facecolor is a list so output is consistent across Pythons
facecolor = list(facecolor)
ii, jj, kk = simplices.T

# make a colorscale from the colors
colorscale = FigureFactory._make_colorscale(colormap)
colorscale = FigureFactory._convert_colorscale_to_rgb(colorscale)

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

colorbar = graph_objs.Mesh3d(x=[0, 1], y=[0, 1], z=[0, 1],
colorscale=colorscale,
intensity=[0, 1],
showscale=True)
mean_dists_are_numbers = not isinstance(mean_dists[0], str)

if mean_dists_are_numbers and show_colorbar is True:
# make a colorscale from the colors
colorscale = FigureFactory._make_colorscale(colormap)
colorscale = FigureFactory._convert_colorscale_to_rgb(colorscale)

colorbar = graph_objs.Scatter3d(
x=x[0],
y=y[0],
z=z[0],
mode='markers',
marker=dict(
size=0.1,
color=[min_mean_dists, max_mean_dists],
colorscale=colorscale,
showscale=True),
hoverinfo='None',
showlegend=False
)

# the triangle sides are not plotted
if plot_edges is not True:
if show_colorbar is True:
if plot_edges is False:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😛 👍

if mean_dists_are_numbers and show_colorbar is True:
return graph_objs.Data([triangles, colorbar])
else:
return graph_objs.Data([triangles])


# define the lists x_edge, y_edge and z_edge, of x, y, resp z
# coordinates of edge end points for each triangle
# None separates data corresponding to two consecutive triangles
Expand Down Expand Up @@ -3392,10 +3407,14 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
# define the lines for plotting
lines = graph_objs.Scatter3d(
x=x_edge, y=y_edge, z=z_edge, mode='lines',
line=graph_objs.Line(color='rgb(50, 50, 50)',
width=1.5)
line=graph_objs.Line(
color=edges_color,
width=1.5
),
showlegend=False
)
if show_colorbar is True:

if mean_dists_are_numbers and show_colorbar is True:
return graph_objs.Data([triangles, lines, colorbar])
else:
return graph_objs.Data([triangles, lines])
Expand All @@ -3407,6 +3426,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
backgroundcolor='rgb(230, 230, 230)',
gridcolor='rgb(255, 255, 255)',
zerolinecolor='rgb(255, 255, 255)',
edges_color='rgb(50, 50, 50)',
height=800, width=800,
aspectratio=dict(x=1, y=1, z=1)):
"""
Expand All @@ -3428,7 +3448,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
: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
simplices. If None, coloring 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
Expand All @@ -3440,6 +3460,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
inclusive
:param (str) zerolinecolor: color of the axes. Takes a string of the
form 'rgb(x,y,z)' x,y,z are between 0 and 255 inclusive
:param (str) edges_color: color of the edges, if plot_edges is True
:param (int|float) height: the height of the plot (in pixels)
:param (int|float) width: the width of the plot (in pixels)
:param (dict) aspectratio: a dictionary of the aspect ratio values for
Expand Down Expand Up @@ -3475,7 +3496,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
colormap="Blues",
simplices=simplices)
# Plot the data
py.iplot(fig1, filename='Trisurf Plot - Sphere')
py.iplot(fig1, filename='trisurf-plot-sphere')
```

Example 2: Torus
Expand Down Expand Up @@ -3505,10 +3526,10 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,

# Create a figure
fig1 = FF.create_trisurf(x=x, y=y, z=z,
colormap="Portland",
colormap="Greys",
simplices=simplices)
# Plot the data
py.iplot(fig1, filename='Trisurf Plot - Torus')
py.iplot(fig1, filename='trisurf-plot-torus')
```

Example 3: Mobius Band
Expand Down Expand Up @@ -3539,10 +3560,10 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,

# Create a figure
fig1 = FF.create_trisurf(x=x, y=y, z=z,
colormap=[(0.2, 0.4, 0.6),(1, 1, 1)],
colormap=[(0.2, 0.4, 0.6), (1, 1, 1)],
simplices=simplices)
# Plot the data
py.iplot(fig1, filename='Trisurf Plot - Mobius Band')
py.iplot(fig1, filename='trisurf-plot-mobius-band')
```

Example 4: Using a Custom Colormap Function with Light Cone
Expand Down Expand Up @@ -3582,7 +3603,7 @@ def dist_origin(x, y, z):
simplices=simplices,
color_func=dist_origin)
# Plot the data
py.iplot(fig1, filename='Trisurf Plot - Custom Coloring')
py.iplot(fig1, filename='trisurf-plot-custom-coloring')
```

Example 5: Enter color_func as a list of colors
Expand Down Expand Up @@ -3622,10 +3643,11 @@ def dist_origin(x, y, z):
x, y, z, simplices,
color_func=colors,
show_colorbar=True,
edges_color='rgb(2, 85, 180)',
title=' Modern Art'
)

py.iplot(fig, filename="Modern Art")
py.iplot(fig, filename="trisurf-plot-modern-art")
```
"""
from plotly.graph_objs import graph_objs
Expand All @@ -3637,6 +3659,7 @@ def dist_origin(x, y, z):
show_colorbar=show_colorbar,
color_func=color_func,
colormap=colormap,
edges_color=edges_color,
plot_edges=plot_edges)
axis = dict(
showbackground=showbackground,
Expand Down
2 changes: 1 addition & 1 deletion plotly/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.12.8'
__version__ = '1.12.9'