Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 809037b

Browse filesBrowse files
authored
Merge pull request plotly#551 from plotly/trisurf-colorbar-range
added appropriate colorbar max and min values, edges_color to param for line coloring, and making code more clear
2 parents 8e234c9 + 1165bec commit 809037b
Copy full SHA for 809037b

File tree

Expand file treeCollapse file tree

4 files changed

+101
-139
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+101
-139
lines changed

‎plotly/tests/test_optional/temp-plot.html

Copy file name to clipboardExpand all lines: plotly/tests/test_optional/temp-plot.html
-60Lines changed: 0 additions & 60 deletions
This file was deleted.

‎plotly/tests/test_optional/test_figure_factory.py

Copy file name to clipboardExpand all lines: plotly/tests/test_optional/test_figure_factory.py
+50-51Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -842,29 +842,28 @@ def test_trisurf_all_args(self):
842842
)
843843

844844
exp_trisurf_plot = {
845-
'data': [{'facecolor': np.array(
846-
['rgb(144, 94, 132)',
847-
'rgb(23, 190, 207)',
848-
'rgb(144, 94, 132)',
849-
'rgb(31, 119, 180)',
850-
'rgb(144, 94, 132)',
851-
'rgb(31, 119, 180)',
852-
'rgb(144, 94, 132)',
853-
'rgb(23, 190, 207)']
854-
),
855-
'i': np.array([3, 1, 1, 5, 7, 3, 5, 7]),
856-
'j': np.array([1, 3, 5, 1, 3, 7, 7, 5]),
857-
'k': np.array([4, 0, 4, 2, 4, 6, 4, 8]),
858-
'name': '',
859-
'type': 'mesh3d',
860-
'x': np.array([-1., 0., 1., -1., 0., 1.,
861-
-1., 0., 1.]),
862-
'y': np.array([-1., -1., -1., 0., 0., 0.,
863-
1., 1., 1.]),
864-
'z': np.array([1., -0., -1., -0., 0., 0.,
865-
-1., 0., 1.])},
845+
'data': [{'facecolor': ['rgb(144, 94, 132)',
846+
'rgb(23, 190, 207)',
847+
'rgb(144, 94, 132)',
848+
'rgb(31, 119, 180)',
849+
'rgb(144, 94, 132)',
850+
'rgb(31, 119, 180)',
851+
'rgb(144, 94, 132)',
852+
'rgb(23, 190, 207)'],
853+
'i': np.array([3, 1, 1, 5, 7, 3, 5, 7]),
854+
'j': np.array([1, 3, 5, 1, 3, 7, 7, 5]),
855+
'k': np.array([4, 0, 4, 2, 4, 6, 4, 8]),
856+
'name': '',
857+
'type': 'mesh3d',
858+
'x': np.array([-1., 0., 1., -1., 0.,
859+
1., -1., 0., 1.]),
860+
'y': np.array([-1., -1., -1., 0., 0.,
861+
0., 1., 1., 1.]),
862+
'z': np.array([1., -0., -1., -0., 0.,
863+
0., -1., 0., 1.])},
866864
{'line': {'color': 'rgb(50, 50, 50)', 'width': 1.5},
867865
'mode': 'lines',
866+
'showlegend': False,
868867
'type': 'scatter3d',
869868
'x': np.array([-1.0, 0.0, 0.0, -1.0, None, 0.0, -1.0,
870869
-1.0, 0.0, None, 0.0, 1.0, 0.0, 0.0,
@@ -884,43 +883,43 @@ def test_trisurf_all_args(self):
884883
-0.0, 0.0, 0.0, None, -0.0, 0.0, -1.0,
885884
-0.0, None, 0.0, 0.0, 0.0, 0.0, None,
886885
0.0, 0.0, 1.0, 0.0, None])},
887-
{'colorscale': [[0.0, 'rgb(31, 119, 180)'],
888-
[0.1111111111111111, 'rgb(255, 127, 14)'],
889-
[0.2222222222222222, 'rgb(44, 160, 44)'],
890-
[0.3333333333333333, 'rgb(214, 39, 40)'],
891-
[0.4444444444444444, 'rgb(148, 103, 189)'],
892-
[0.5555555555555556, 'rgb(140, 86, 75)'],
893-
[0.6666666666666666, 'rgb(227, 119, 194)'],
894-
[0.7777777777777778, 'rgb(127, 127, 127)'],
895-
[0.8888888888888888, 'rgb(188, 189, 34)'],
896-
[1.0, 'rgb(23, 190, 207)']],
897-
'intensity': [0, 1],
898-
'showscale': True,
899-
'type': 'mesh3d',
900-
'x': [0, 1],
901-
'y': [0, 1],
902-
'z': [0, 1]}],
886+
{'hoverinfo': 'None',
887+
'marker': {'color': [-0.33333333333333331,
888+
0.33333333333333331],
889+
'colorscale': [
890+
[0.0, 'rgb(31, 119, 180)'],
891+
[0.1111111111111111, 'rgb(255, 127, 14)'],
892+
[0.2222222222222222, 'rgb(44, 160, 44)'],
893+
[0.3333333333333333, 'rgb(214, 39, 40)'],
894+
[0.4444444444444444, 'rgb(148, 103, 189)'],
895+
[0.5555555555555556, 'rgb(140, 86, 75)'],
896+
[0.6666666666666666, 'rgb(227, 119, 194)'],
897+
[0.7777777777777778, 'rgb(127, 127, 127)'],
898+
[0.8888888888888888, 'rgb(188, 189, 34)'],
899+
[1.0, 'rgb(23, 190, 207)']
900+
],
901+
'showscale': True,
902+
'size': 0.1},
903+
'mode': 'markers',
904+
'showlegend': False,
905+
'type': 'scatter3d',
906+
'x': -1.0,
907+
'y': -1.0,
908+
'z': 1.0}],
903909
'layout': {'height': 800,
904910
'scene': {'aspectratio': {'x': 1, 'y': 1, 'z': 1},
905-
'xaxis': {'backgroundcolor':
906-
'rgb(230, 230, 230)',
907-
'gridcolor':
908-
'rgb(255, 255, 255)',
911+
'xaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
912+
'gridcolor': 'rgb(255, 255, 255)',
909913
'showbackground': True,
910-
'zerolinecolor':
911-
'rgb(255, 255, 255)'},
912-
'yaxis': {'backgroundcolor':
913-
'rgb(230, 230, 230)',
914+
'zerolinecolor': 'rgb(255, 255, 255)'},
915+
'yaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
914916
'gridcolor': 'rgb(255, 255, 255)',
915917
'showbackground': True,
916-
'zerolinecolor':
917-
'rgb(255, 255, 255)'},
918-
'zaxis': {'backgroundcolor':
919-
'rgb(230, 230, 230)',
918+
'zerolinecolor': 'rgb(255, 255, 255)'},
919+
'zaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
920920
'gridcolor': 'rgb(255, 255, 255)',
921921
'showbackground': True,
922-
'zerolinecolor':
923-
'rgb(255, 255, 255)'}},
922+
'zerolinecolor': 'rgb(255, 255, 255)'}},
924923
'title': 'Trisurf Plot',
925924
'width': 800}
926925
}

‎plotly/tools.py

Copy file name to clipboardExpand all lines: plotly/tools.py
+50-27Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,9 +3269,9 @@ def _map_face2color(face, colormap, vmin, vmax):
32693269
return face_color
32703270

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

3300-
# convert all colors to rgb
3300+
# convert all colors in color_func to rgb
33013301
for index in range(len(color_func)):
33023302
if isinstance(color_func[index], str):
33033303
if '#' in color_func[index]:
33043304
foo = FigureFactory._hex_to_rgb(color_func[index])
33053305
color_func[index] = FigureFactory._label_rgb(foo)
33063306

3307+
if isinstance(color_func[index], tuple):
3308+
foo = FigureFactory._convert_to_RGB_255(color_func[index])
3309+
color_func[index] = FigureFactory._label_rgb(foo)
3310+
33073311
mean_dists = np.asarray(color_func)
33083312
else:
33093313
# apply user inputted function to calculate
@@ -3333,30 +3337,41 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
33333337
max_mean_dists)
33343338
facecolor.append(color)
33353339

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

3340-
# make a colorscale from the colors
3341-
colorscale = FigureFactory._make_colorscale(colormap)
3342-
colorscale = FigureFactory._convert_colorscale_to_rgb(colorscale)
3343-
33443344
triangles = graph_objs.Mesh3d(x=x, y=y, z=z, facecolor=facecolor,
33453345
i=ii, j=jj, k=kk, name='')
33463346

3347-
colorbar = graph_objs.Mesh3d(x=[0, 1], y=[0, 1], z=[0, 1],
3348-
colorscale=colorscale,
3349-
intensity=[0, 1],
3350-
showscale=True)
3347+
mean_dists_are_numbers = not isinstance(mean_dists[0], str)
3348+
3349+
if mean_dists_are_numbers and show_colorbar is True:
3350+
# make a colorscale from the colors
3351+
colorscale = FigureFactory._make_colorscale(colormap)
3352+
colorscale = FigureFactory._convert_colorscale_to_rgb(colorscale)
3353+
3354+
colorbar = graph_objs.Scatter3d(
3355+
x=x[0],
3356+
y=y[0],
3357+
z=z[0],
3358+
mode='markers',
3359+
marker=dict(
3360+
size=0.1,
3361+
color=[min_mean_dists, max_mean_dists],
3362+
colorscale=colorscale,
3363+
showscale=True),
3364+
hoverinfo='None',
3365+
showlegend=False
3366+
)
33513367

33523368
# the triangle sides are not plotted
3353-
if plot_edges is not True:
3354-
if show_colorbar is True:
3369+
if plot_edges is False:
3370+
if mean_dists_are_numbers and show_colorbar is True:
33553371
return graph_objs.Data([triangles, colorbar])
33563372
else:
33573373
return graph_objs.Data([triangles])
33583374

3359-
33603375
# define the lists x_edge, y_edge and z_edge, of x, y, resp z
33613376
# coordinates of edge end points for each triangle
33623377
# None separates data corresponding to two consecutive triangles
@@ -3392,10 +3407,14 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
33923407
# define the lines for plotting
33933408
lines = graph_objs.Scatter3d(
33943409
x=x_edge, y=y_edge, z=z_edge, mode='lines',
3395-
line=graph_objs.Line(color='rgb(50, 50, 50)',
3396-
width=1.5)
3410+
line=graph_objs.Line(
3411+
color=edges_color,
3412+
width=1.5
3413+
),
3414+
showlegend=False
33973415
)
3398-
if show_colorbar is True:
3416+
3417+
if mean_dists_are_numbers and show_colorbar is True:
33993418
return graph_objs.Data([triangles, lines, colorbar])
34003419
else:
34013420
return graph_objs.Data([triangles, lines])
@@ -3407,6 +3426,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
34073426
backgroundcolor='rgb(230, 230, 230)',
34083427
gridcolor='rgb(255, 255, 255)',
34093428
zerolinecolor='rgb(255, 255, 255)',
3429+
edges_color='rgb(50, 50, 50)',
34103430
height=800, width=800,
34113431
aspectratio=dict(x=1, y=1, z=1)):
34123432
"""
@@ -3428,7 +3448,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
34283448
:param (function|list) color_func: The parameter that determines the
34293449
coloring of the surface. Takes either a function with 3 arguments
34303450
x, y, z or a list/array of color values the same length as
3431-
simplices. If set to None, color will only depend on the z axis
3451+
simplices. If None, coloring will only depend on the z axis
34323452
:param (str) title: title of the plot
34333453
:param (bool) plot_edges: determines if the triangles on the trisurf
34343454
are visible
@@ -3440,6 +3460,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
34403460
inclusive
34413461
:param (str) zerolinecolor: color of the axes. Takes a string of the
34423462
form 'rgb(x,y,z)' x,y,z are between 0 and 255 inclusive
3463+
:param (str) edges_color: color of the edges, if plot_edges is True
34433464
:param (int|float) height: the height of the plot (in pixels)
34443465
:param (int|float) width: the width of the plot (in pixels)
34453466
:param (dict) aspectratio: a dictionary of the aspect ratio values for
@@ -3475,7 +3496,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
34753496
colormap="Blues",
34763497
simplices=simplices)
34773498
# Plot the data
3478-
py.iplot(fig1, filename='Trisurf Plot - Sphere')
3499+
py.iplot(fig1, filename='trisurf-plot-sphere')
34793500
```
34803501
34813502
Example 2: Torus
@@ -3505,10 +3526,10 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
35053526
35063527
# Create a figure
35073528
fig1 = FF.create_trisurf(x=x, y=y, z=z,
3508-
colormap="Portland",
3529+
colormap="Greys",
35093530
simplices=simplices)
35103531
# Plot the data
3511-
py.iplot(fig1, filename='Trisurf Plot - Torus')
3532+
py.iplot(fig1, filename='trisurf-plot-torus')
35123533
```
35133534
35143535
Example 3: Mobius Band
@@ -3539,10 +3560,10 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
35393560
35403561
# Create a figure
35413562
fig1 = FF.create_trisurf(x=x, y=y, z=z,
3542-
colormap=[(0.2, 0.4, 0.6),(1, 1, 1)],
3563+
colormap=[(0.2, 0.4, 0.6), (1, 1, 1)],
35433564
simplices=simplices)
35443565
# Plot the data
3545-
py.iplot(fig1, filename='Trisurf Plot - Mobius Band')
3566+
py.iplot(fig1, filename='trisurf-plot-mobius-band')
35463567
```
35473568
35483569
Example 4: Using a Custom Colormap Function with Light Cone
@@ -3582,7 +3603,7 @@ def dist_origin(x, y, z):
35823603
simplices=simplices,
35833604
color_func=dist_origin)
35843605
# Plot the data
3585-
py.iplot(fig1, filename='Trisurf Plot - Custom Coloring')
3606+
py.iplot(fig1, filename='trisurf-plot-custom-coloring')
35863607
```
35873608
35883609
Example 5: Enter color_func as a list of colors
@@ -3622,10 +3643,11 @@ def dist_origin(x, y, z):
36223643
x, y, z, simplices,
36233644
color_func=colors,
36243645
show_colorbar=True,
3646+
edges_color='rgb(2, 85, 180)',
36253647
title=' Modern Art'
36263648
)
36273649
3628-
py.iplot(fig, filename="Modern Art")
3650+
py.iplot(fig, filename="trisurf-plot-modern-art")
36293651
```
36303652
"""
36313653
from plotly.graph_objs import graph_objs
@@ -3637,6 +3659,7 @@ def dist_origin(x, y, z):
36373659
show_colorbar=show_colorbar,
36383660
color_func=color_func,
36393661
colormap=colormap,
3662+
edges_color=edges_color,
36403663
plot_edges=plot_edges)
36413664
axis = dict(
36423665
showbackground=showbackground,

‎plotly/version.py

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.12.8'
1+
__version__ = '1.12.9'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.