46
46
'Blackbody' : ['rgb(0,0,0)' , 'rgb(160,200,255)' ],
47
47
'Earth' : ['rgb(0,0,130)' , 'rgb(255,255,255)' ],
48
48
'Electric' : ['rgb(0,0,0)' , 'rgb(255,250,220)' ],
49
- 'Viridis' : 'Viridis' }
50
- #['rgb(68,1,84)', 'rgb(253,231,37)']}
49
+ 'Viridis' : ['rgb(68,1,84)' , 'rgb(253,231,37)' ]}
51
50
52
51
# color constants for violin plot
53
52
DEFAULT_FILLCOLOR = '#1f77b4'
@@ -1478,18 +1477,42 @@ class FigureFactory(object):
1478
1477
"""
1479
1478
1480
1479
@staticmethod
1481
- def _make_colorscale (colors ):
1480
+ def _make_colorscale (colors , scale = None ):
1482
1481
"""
1483
- Makes a list of colors into a colorscale-acceptable form
1482
+ Makes a colorscale from a list of colors and scale
1484
1483
1484
+ Takes a list of colors and scales and constructs a colorscale based
1485
+ on the colors in sequential order. If 'scale' is left empty, a linear-
1486
+ interpolated colorscale will be generated. If 'scale' is a specificed
1487
+ list, it must be the same legnth as colors and must contain all floats
1485
1488
For documentation regarding to the form of the output, see
1486
1489
https://plot.ly/python/reference/#mesh3d-colorscale
1487
1490
"""
1488
1491
colorscale = []
1489
- diff = 1. / (len (colors ) - 1 )
1490
1492
1491
- for j in range (len (colors )):
1492
- colorscale .append ([j * diff , colors [j ]])
1493
+ if not scale :
1494
+ for j in range (len (colors )):
1495
+ colorscale .append ([j * 1. / (len (colors ) - 1 ), colors [j ]])
1496
+ return colorscale
1497
+
1498
+ else :
1499
+ colorscale = [[scale [j ], colors [j ]] for j in range (len (colors ))]
1500
+ return colorscale
1501
+
1502
+ @staticmethod
1503
+ def _convert_colorscale_to_rgb (colorscale ):
1504
+ """
1505
+ Converts the colors in a colorscale to rgb colors
1506
+ """
1507
+ for index in range (len (colorscale )):
1508
+ colorscale [index ][1 ] = FigureFactory ._convert_to_RGB_255 (
1509
+ colorscale [index ][1 ]
1510
+ )
1511
+
1512
+ for index in range (len (colorscale )):
1513
+ colorscale [index ][1 ] = FigureFactory ._label_rgb (
1514
+ colorscale [index ][1 ]
1515
+ )
1493
1516
return colorscale
1494
1517
1495
1518
@staticmethod
@@ -2996,7 +3019,7 @@ def _find_intermediate_color(lowcolor, highcolor, intermed):
2996
3019
@staticmethod
2997
3020
def _color_parser (colors , function ):
2998
3021
"""
2999
- Takes color(s) and a function and applys the function on the color(s)
3022
+ Takes color(s) and a function and applies the function on the color(s)
3000
3023
3001
3024
In particular, this function identifies whether the given color object
3002
3025
is an iterable or not and applies the given color-parsing function to
@@ -3081,9 +3104,9 @@ def _map_face2color(face, colormap, vmin, vmax):
3081
3104
return face_color
3082
3105
3083
3106
@staticmethod
3084
- def _trisurf (x , y , z , simplices , colormap = None , color_func = None ,
3085
- plot_edges = False , x_edge = None , y_edge = None , z_edge = None ,
3086
- facecolor = None ):
3107
+ def _trisurf (x , y , z , simplices , show_colorbar , colormap = None ,
3108
+ color_func = None , plot_edges = False , x_edge = None , y_edge = None ,
3109
+ z_edge = None , facecolor = None ):
3087
3110
"""
3088
3111
Refer to FigureFactory.create_trisurf() for docstring
3089
3112
"""
@@ -3149,26 +3172,25 @@ def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
3149
3172
facecolor = np .asarray (facecolor )
3150
3173
ii , jj , kk = simplices .T
3151
3174
3152
- # Adding intensity to Mesh3D Data
3153
- intensity = [0 ]
3175
+ # make a colorscale from the colors
3176
+ colorscale = FigureFactory ._make_colorscale (colormap )
3177
+ colorscale = FigureFactory ._convert_colorscale_to_rgb (colorscale )
3154
3178
3155
- div = 1. / (len (x ) - 1 )
3156
-
3157
- for j in range (1 , len (x )+ 1 ):
3158
- intensity .append (j * div )
3159
- #print intensity
3160
- #intensity = [0 for j in range(len(x))]
3179
+ triangles = graph_objs .Mesh3d (x = x , y = y , z = z , facecolor = facecolor ,
3180
+ i = ii , j = jj , k = kk , name = '' )
3161
3181
3162
- colorscale_numbered = FigureFactory ._make_colorscale (colormap )
3182
+ colorbar = graph_objs .Mesh3d (x = [0 , 1 ], y = [0 , 1 ], z = [0 , 1 ],
3183
+ colorscale = colorscale ,
3184
+ intensity = [0 , 1 ],
3185
+ showscale = True )
3163
3186
3164
- triangles = graph_objs .Mesh3d (x = x , y = y , z = z , facecolor = facecolor ,
3165
- i = ii , j = jj , k = kk , name = '' ,
3166
- intensity = intensity ,
3167
- colorscale = colorscale_numbered ,
3168
- showscale = True )
3187
+ # the triangle sides are not plotted
3188
+ if plot_edges is not True :
3189
+ if show_colorbar is True :
3190
+ return graph_objs .Data ([triangles , colorbar ])
3191
+ else :
3192
+ return graph_objs .Data ([triangles ])
3169
3193
3170
- if plot_edges is not True : # the triangle sides are not plotted
3171
- return graph_objs .Data ([triangles ])
3172
3194
3173
3195
# define the lists x_edge, y_edge and z_edge, of x, y, resp z
3174
3196
# coordinates of edge end points for each triangle
@@ -3208,12 +3230,14 @@ def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
3208
3230
line = graph_objs .Line (color = 'rgb(50, 50, 50)' ,
3209
3231
width = 1.5 )
3210
3232
)
3211
-
3212
- return graph_objs .Data ([triangles , lines ])
3233
+ if show_colorbar is True :
3234
+ return graph_objs .Data ([triangles , lines , colorbar ])
3235
+ else :
3236
+ return graph_objs .Data ([triangles , lines ])
3213
3237
3214
3238
@staticmethod
3215
- def create_trisurf (x , y , z , simplices , colormap = None , color_func = None ,
3216
- title = 'Trisurf Plot' , plot_edges = True ,
3239
+ def create_trisurf (x , y , z , simplices , colormap = None , show_colorbar = True ,
3240
+ color_func = None , title = 'Trisurf Plot' , plot_edges = True ,
3217
3241
showbackground = True ,
3218
3242
backgroundcolor = 'rgb(230, 230, 230)' ,
3219
3243
gridcolor = 'rgb(255, 255, 255)' ,
@@ -3234,7 +3258,8 @@ def create_trisurf(x, y, z, simplices, colormap=None, color_func=None,
3234
3258
of the form 'rgb(x, y, z)' where x, y, z belong to the interval
3235
3259
[0, 255] and a color tuple is a tuple of the form (a, b, c) where
3236
3260
a, b and c belong to [0, 1]. If colormap is a list, it must
3237
- contain the valid color types aforementioned as its members.
3261
+ contain the valid color types aforementioned as its members
3262
+ :param (bool) show_colorbar: determines if colorbar is visible
3238
3263
:param (function|list) color_func: The parameter that determines the
3239
3264
coloring of the surface. Takes either a function with 3 arguments
3240
3265
x, y, z or a list/array of color values the same length as
@@ -3443,6 +3468,7 @@ def dist_origin(x, y, z):
3443
3468
colormap = FigureFactory ._validate_colors (colormap , 'tuple' )
3444
3469
3445
3470
data1 = FigureFactory ._trisurf (x , y , z , simplices ,
3471
+ show_colorbar = show_colorbar ,
3446
3472
color_func = color_func ,
3447
3473
colormap = colormap ,
3448
3474
plot_edges = plot_edges )
0 commit comments