@@ -3269,9 +3269,9 @@ def _map_face2color(face, colormap, vmin, vmax):
3269
3269
return face_color
3270
3270
3271
3271
@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 ):
3275
3275
"""
3276
3276
Refer to FigureFactory.create_trisurf() for docstring
3277
3277
"""
@@ -3297,13 +3297,17 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
3297
3297
raise ValueError ("If color_func is a list/array, it must "
3298
3298
"be the same length as simplices." )
3299
3299
3300
- # convert all colors to rgb
3300
+ # convert all colors in color_func to rgb
3301
3301
for index in range (len (color_func )):
3302
3302
if isinstance (color_func [index ], str ):
3303
3303
if '#' in color_func [index ]:
3304
3304
foo = FigureFactory ._hex_to_rgb (color_func [index ])
3305
3305
color_func [index ] = FigureFactory ._label_rgb (foo )
3306
3306
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
+
3307
3311
mean_dists = np .asarray (color_func )
3308
3312
else :
3309
3313
# apply user inputted function to calculate
@@ -3333,30 +3337,41 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
3333
3337
max_mean_dists )
3334
3338
facecolor .append (color )
3335
3339
3336
- # Make sure we have arrays to speed up plotting
3340
+ # Make sure facecolor is a list so output is consistent across Pythons
3337
3341
facecolor = list (facecolor )
3338
3342
ii , jj , kk = simplices .T
3339
3343
3340
- # make a colorscale from the colors
3341
- colorscale = FigureFactory ._make_colorscale (colormap )
3342
- colorscale = FigureFactory ._convert_colorscale_to_rgb (colorscale )
3343
-
3344
3344
triangles = graph_objs .Mesh3d (x = x , y = y , z = z , facecolor = facecolor ,
3345
3345
i = ii , j = jj , k = kk , name = '' )
3346
3346
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
+ )
3351
3367
3352
3368
# 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 :
3355
3371
return graph_objs .Data ([triangles , colorbar ])
3356
3372
else :
3357
3373
return graph_objs .Data ([triangles ])
3358
3374
3359
-
3360
3375
# define the lists x_edge, y_edge and z_edge, of x, y, resp z
3361
3376
# coordinates of edge end points for each triangle
3362
3377
# None separates data corresponding to two consecutive triangles
@@ -3392,10 +3407,14 @@ def _trisurf(x, y, z, simplices, show_colorbar, colormap=None,
3392
3407
# define the lines for plotting
3393
3408
lines = graph_objs .Scatter3d (
3394
3409
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
3397
3415
)
3398
- if show_colorbar is True :
3416
+
3417
+ if mean_dists_are_numbers and show_colorbar is True :
3399
3418
return graph_objs .Data ([triangles , lines , colorbar ])
3400
3419
else :
3401
3420
return graph_objs .Data ([triangles , lines ])
@@ -3407,6 +3426,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
3407
3426
backgroundcolor = 'rgb(230, 230, 230)' ,
3408
3427
gridcolor = 'rgb(255, 255, 255)' ,
3409
3428
zerolinecolor = 'rgb(255, 255, 255)' ,
3429
+ edges_color = 'rgb(50, 50, 50)' ,
3410
3430
height = 800 , width = 800 ,
3411
3431
aspectratio = dict (x = 1 , y = 1 , z = 1 )):
3412
3432
"""
@@ -3428,7 +3448,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
3428
3448
:param (function|list) color_func: The parameter that determines the
3429
3449
coloring of the surface. Takes either a function with 3 arguments
3430
3450
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
3432
3452
:param (str) title: title of the plot
3433
3453
:param (bool) plot_edges: determines if the triangles on the trisurf
3434
3454
are visible
@@ -3440,6 +3460,7 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
3440
3460
inclusive
3441
3461
:param (str) zerolinecolor: color of the axes. Takes a string of the
3442
3462
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
3443
3464
:param (int|float) height: the height of the plot (in pixels)
3444
3465
:param (int|float) width: the width of the plot (in pixels)
3445
3466
: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,
3475
3496
colormap="Blues",
3476
3497
simplices=simplices)
3477
3498
# Plot the data
3478
- py.iplot(fig1, filename='Trisurf Plot - Sphere ')
3499
+ py.iplot(fig1, filename='trisurf-plot-sphere ')
3479
3500
```
3480
3501
3481
3502
Example 2: Torus
@@ -3505,10 +3526,10 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
3505
3526
3506
3527
# Create a figure
3507
3528
fig1 = FF.create_trisurf(x=x, y=y, z=z,
3508
- colormap="Portland ",
3529
+ colormap="Greys ",
3509
3530
simplices=simplices)
3510
3531
# Plot the data
3511
- py.iplot(fig1, filename='Trisurf Plot - Torus ')
3532
+ py.iplot(fig1, filename='trisurf-plot-torus ')
3512
3533
```
3513
3534
3514
3535
Example 3: Mobius Band
@@ -3539,10 +3560,10 @@ def create_trisurf(x, y, z, simplices, colormap=None, show_colorbar=True,
3539
3560
3540
3561
# Create a figure
3541
3562
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)],
3543
3564
simplices=simplices)
3544
3565
# Plot the data
3545
- py.iplot(fig1, filename='Trisurf Plot - Mobius Band ')
3566
+ py.iplot(fig1, filename='trisurf-plot-mobius-band ')
3546
3567
```
3547
3568
3548
3569
Example 4: Using a Custom Colormap Function with Light Cone
@@ -3582,7 +3603,7 @@ def dist_origin(x, y, z):
3582
3603
simplices=simplices,
3583
3604
color_func=dist_origin)
3584
3605
# Plot the data
3585
- py.iplot(fig1, filename='Trisurf Plot - Custom Coloring ')
3606
+ py.iplot(fig1, filename='trisurf-plot-custom-coloring ')
3586
3607
```
3587
3608
3588
3609
Example 5: Enter color_func as a list of colors
@@ -3622,10 +3643,11 @@ def dist_origin(x, y, z):
3622
3643
x, y, z, simplices,
3623
3644
color_func=colors,
3624
3645
show_colorbar=True,
3646
+ edges_color='rgb(2, 85, 180)',
3625
3647
title=' Modern Art'
3626
3648
)
3627
3649
3628
- py.iplot(fig, filename="Modern Art ")
3650
+ py.iplot(fig, filename="trisurf-plot-modern-art ")
3629
3651
```
3630
3652
"""
3631
3653
from plotly .graph_objs import graph_objs
@@ -3637,6 +3659,7 @@ def dist_origin(x, y, z):
3637
3659
show_colorbar = show_colorbar ,
3638
3660
color_func = color_func ,
3639
3661
colormap = colormap ,
3662
+ edges_color = edges_color ,
3640
3663
plot_edges = plot_edges )
3641
3664
axis = dict (
3642
3665
showbackground = showbackground ,
0 commit comments