@@ -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 ,
0 commit comments