@@ -1510,25 +1510,28 @@ def _map_z2color(zval, colormap, vmin, vmax):
1510
1510
# is normalized to be between 0 and 1
1511
1511
t = (zval - vmin )/ float ((vmax - vmin ))
1512
1512
1513
- # for colormaps of more than 2 colors, find adjacent colors in color
1514
- # map that the intermediate color is between
1515
- num_steps = len (colormap ) - 1
1516
- step = 1. / num_steps
1517
-
1518
- if t == 1.0 :
1519
- t_color = FigureFactory ._find_intermediate_color (
1520
- colormap [int (t / step ) - 1 ],
1521
- colormap [int (t / step )],
1522
- t
1523
- )
1513
+ # for colormaps of more than 2 colors, find two closest colors based
1514
+ # on relative position between vmin and vmax
1515
+ if len (colormap ) == 1 :
1516
+ t_color = colormap [0 ]
1524
1517
else :
1525
- new_t = (t - int (t / step )* step )/ float (step )
1518
+ num_steps = len (colormap ) - 1
1519
+ step = 1. / num_steps
1520
+
1521
+ if t == 1.0 :
1522
+ t_color = FigureFactory ._find_intermediate_color (
1523
+ colormap [int (t / step ) - 1 ],
1524
+ colormap [int (t / step )],
1525
+ t
1526
+ )
1527
+ else :
1528
+ new_t = (t - int (t / step )* step )/ float (step )
1526
1529
1527
- t_color = FigureFactory ._find_intermediate_color (
1528
- colormap [int (t / step )],
1529
- colormap [int (t / step ) + 1 ],
1530
- new_t
1531
- )
1530
+ t_color = FigureFactory ._find_intermediate_color (
1531
+ colormap [int (t / step )],
1532
+ colormap [int (t / step ) + 1 ],
1533
+ new_t
1534
+ )
1532
1535
1533
1536
t_color = (t_color [0 ]* 255.0 , t_color [1 ]* 255.0 , t_color [2 ]* 255.0 )
1534
1537
labelled_color = 'rgb{}' .format (t_color )
@@ -1817,33 +1820,6 @@ def dist_origin(x, y, z):
1817
1820
'Electric' : ['rgb(0,0,0)' , 'rgb(255,250,220)' ],
1818
1821
'Viridis' : ['rgb(68,1,84)' , 'rgb(253,231,37)' ]}
1819
1822
1820
- if isinstance (colors , str ):
1821
- if colors in plotly_scales :
1822
- colors = plotly_scales [colors ]
1823
- else :
1824
- if ('rgb' not in colors ) and ('#' not in colors ):
1825
- raise exceptions .PlotlyError ("If you input a string "
1826
- "for 'colors', it must "
1827
- "either be a Plotly "
1828
- "colorscale, an 'rgb' "
1829
- "color, or a hex color." )
1830
- colors_list = []
1831
- colors_list .append (colors )
1832
- colors = colors_list
1833
-
1834
- if not isinstance (colors , list ):
1835
- raise exceptions .PlotlyError ("'colors' needs to be either a "
1836
- "plotly colorscale string or a "
1837
- "list of at least two colors if "
1838
- "use_colorscale is True." )
1839
- if len (colors ) <= 0 :
1840
- raise exceptions .PlotlyError ("Empty list of colors." )
1841
-
1842
- if (not isinstance (data , list )) and data_header is None :
1843
- raise exceptions .PlotlyError ("Please enter a string name for "
1844
- "data_header" )
1845
-
1846
-
1847
1823
# Validate colormap
1848
1824
if colormap is None :
1849
1825
colormap = [DEFAULT_PLOTLY_COLORS [0 ],
@@ -1857,7 +1833,7 @@ def dist_origin(x, y, z):
1857
1833
colormap = FigureFactory ._unlabel_rgb (colormap )
1858
1834
colormap = FigureFactory ._unconvert_from_RGB_255 (colormap )
1859
1835
else :
1860
- if ('rgb' not in colors ) and ('#' not in colors ):
1836
+ if ('rgb' not in colormap ) and ('#' not in colormap ):
1861
1837
scale_keys = list (plotly_scales .keys ())
1862
1838
raise exceptions .PlotlyError ("If you input a string "
1863
1839
"for 'colormap', it must "
@@ -1870,27 +1846,8 @@ def dist_origin(x, y, z):
1870
1846
colors_list = []
1871
1847
colors_list .append (colormap )
1872
1848
colormap = colors_list
1873
-
1874
-
1875
-
1876
-
1877
-
1878
-
1879
-
1880
-
1881
-
1882
- if isinstance (colormap , str ):
1883
- if colormap not in plotly_scales :
1884
- scale_keys = list (plotly_scales .keys ())
1885
- raise exceptions .PlotlyError ("You must pick a valid "
1886
- "plotly colorscale "
1887
- "name from "
1888
- "{}" .format (scale_keys ))
1889
-
1890
- colormap = [plotly_scales [colormap ][0 ],
1891
- plotly_scales [colormap ][1 ]]
1892
- colormap = FigureFactory ._unlabel_rgb (colormap )
1893
- colormap = FigureFactory ._unconvert_from_RGB_255 (colormap )
1849
+ colormap = FigureFactory ._unlabel_rgb (colormap )
1850
+ colormap = FigureFactory ._unconvert_from_RGB_255 (colormap )
1894
1851
1895
1852
else :
1896
1853
if not isinstance (colormap , list ):
0 commit comments