@@ -1468,9 +1468,9 @@ def _find_intermediate_color(lowcolor, highcolor, intermed):
1468
1468
diff_1 = float (highcolor [1 ] - lowcolor [1 ])
1469
1469
diff_2 = float (highcolor [2 ] - lowcolor [2 ])
1470
1470
1471
- inter_colors = np . array ([ lowcolor [0 ] + intermed * diff_0 ,
1472
- lowcolor [1 ] + intermed * diff_1 ,
1473
- lowcolor [2 ] + intermed * diff_2 ] )
1471
+ inter_colors = ( lowcolor [0 ] + intermed * diff_0 ,
1472
+ lowcolor [1 ] + intermed * diff_1 ,
1473
+ lowcolor [2 ] + intermed * diff_2 )
1474
1474
return inter_colors
1475
1475
1476
1476
@staticmethod
@@ -1503,35 +1503,53 @@ def _unconvert_from_RGB_255(colors):
1503
1503
return un_rgb_colors
1504
1504
1505
1505
@staticmethod
1506
- def _map_array2color ( array , colormap , vmin , vmax ):
1506
+ def _map_face2color ( face , colormap , vmin , vmax ):
1507
1507
"""
1508
- Normalize values in array by vmin/vmax and return plotly color strings.
1508
+ Normalize facecolor values by vmin/vmax and return rgb- color strings
1509
1509
1510
- This function takes an array of values along with a colormap and a
1511
- minimum (vmin) and maximum (vmax) range of possible z values for the
1512
- given parametrized surface. It returns an rgb color based on the
1513
- relative position of zval between vmin and vmax
1510
+ This function takes a tuple color with elements between 0 and 1, along
1511
+ with a colormap and a minimum (vmin) and maximum (vmax) range of
1512
+ possible mean distances for the given parametrized surface. It returns
1513
+ an rgb color based on the mean distance between vmin and vmax
1514
1514
1515
1515
"""
1516
1516
if vmin >= vmax :
1517
1517
raise exceptions .PlotlyError ("Incorrect relation between vmin "
1518
1518
"and vmax. The vmin value cannot be "
1519
1519
"bigger than or equal to the value "
1520
1520
"of vmax." )
1521
- # find distance t of zval from vmin to vmax where the distance
1522
- # is normalized to be between 0 and 1
1523
- t = (array - vmin ) / float ((vmax - vmin ))
1524
- t_colors = FigureFactory ._find_intermediate_color (colormap [0 ],
1525
- colormap [1 ],
1526
- t )
1527
- t_colors = t_colors * 255.
1528
- labelled_colors = ['rgb(%s, %s, %s)' % (i , j , k )
1529
- for i , j , k in t_colors .T ]
1530
- return labelled_colors
1521
+ # find the normalized distance t of a triangle face between vmin and
1522
+ #vmax where the distance is normalized between 0 and 1
1523
+ t = (face - vmin ) / float ((vmax - vmin ))
1524
+
1525
+ if len (colormap ) <= 1 :
1526
+ t_color = colormap [0 ]
1527
+ color = FigureFactory ._convert_to_RGB_255 (t_color )
1528
+ color = FigureFactory ._label_rgb (color )
1529
+ else :
1530
+ # account for colormaps with more than one color
1531
+ incr = 1. / (len (colormap ) - 1 )
1532
+ low_color_index = int (t / incr )
1533
+
1534
+ if t == 1 :
1535
+ t_color = colormap [low_color_index ]
1536
+ color = FigureFactory ._convert_to_RGB_255 (t_color )
1537
+ color = FigureFactory ._label_rgb (color )
1538
+
1539
+ else :
1540
+ t_color = FigureFactory ._find_intermediate_color (
1541
+ colormap [low_color_index ],
1542
+ colormap [low_color_index + 1 ],
1543
+ (t - low_color_index * incr ) / incr )
1544
+ color = FigureFactory ._convert_to_RGB_255 (t_color )
1545
+ color = FigureFactory ._label_rgb (color )
1546
+
1547
+ return color
1531
1548
1532
1549
@staticmethod
1533
1550
def _trisurf (x , y , z , simplices , colormap = None , color_func = None ,
1534
- plot_edges = False , x_edge = None , y_edge = None , z_edge = None ):
1551
+ plot_edges = False , x_edge = None , y_edge = None , z_edge = None ,
1552
+ facecolor = None ):
1535
1553
"""
1536
1554
Refer to FigureFactory.create_trisurf() for docstring
1537
1555
"""
@@ -1556,11 +1574,11 @@ def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
1556
1574
if len (color_func ) != len (simplices ):
1557
1575
raise ValueError ("If color_func is a list/array, it must "
1558
1576
"be the same length as simplices." )
1559
- # convert all colors to rgb
1560
- for index in range (len (color_func )):
1561
- if '#' in color_func [index ]:
1562
- foo = FigureFactory ._hex_to_rgb (color_func [index ])
1563
- color_func [index ] = FigureFactory ._label_rgb (foo )
1577
+ # convert all colors to rgb
1578
+ for index in range (len (color_func )):
1579
+ if '#' in color_func [index ]:
1580
+ foo = FigureFactory ._hex_to_rgb (color_func [index ])
1581
+ color_func [index ] = FigureFactory ._label_rgb (foo )
1564
1582
1565
1583
mean_dists = np .asarray (color_func )
1566
1584
else :
@@ -1581,10 +1599,16 @@ def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
1581
1599
else :
1582
1600
min_mean_dists = np .min (mean_dists )
1583
1601
max_mean_dists = np .max (mean_dists )
1584
- facecolor = FigureFactory ._map_array2color (mean_dists ,
1585
- colormap ,
1586
- min_mean_dists ,
1587
- max_mean_dists )
1602
+
1603
+ if facecolor is None :
1604
+ facecolor = []
1605
+ for index in range (len (mean_dists )):
1606
+ color = FigureFactory ._map_face2color (mean_dists [index ],
1607
+ colormap ,
1608
+ min_mean_dists ,
1609
+ max_mean_dists )
1610
+ facecolor .append (color )
1611
+
1588
1612
# Make sure we have arrays to speed up plotting
1589
1613
facecolor = np .asarray (facecolor )
1590
1614
ii , jj , kk = simplices .T
@@ -2931,11 +2955,13 @@ def _label_rgb(colors):
2931
2955
2932
2956
"""
2933
2957
if isinstance (colors , tuple ):
2934
- return 'rgb{}' . format (colors )
2958
+ return ( 'rgb(%s, %s, %s)' % (colors [ 0 ], colors [ 1 ], colors [ 2 ]) )
2935
2959
else :
2936
2960
colors_label = []
2937
2961
for color in colors :
2938
- color_label = 'rgb{}' .format (color )
2962
+ color_label = ('rgb(%s, %s, %s)' % (color [0 ],
2963
+ color [1 ],
2964
+ color [2 ]))
2939
2965
colors_label .append (color_label )
2940
2966
2941
2967
return colors_label
0 commit comments