Skip to content

Commit

Permalink
dendrogram works with scipy===1.5.0 default colors
Browse files Browse the repository at this point in the history
The default colorscale for _dendrogram contains color names compatible
with the default colors given by scipy===1.5.0. It is still backwards
compatible with older scipy versions.
  • Loading branch information
nicholas-esterer committed Jul 10, 2020
1 parent d601477 commit 21b38ab
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions packages/python/plotly/plotly/figure_factory/_dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,45 @@ def get_color_dict(self, colorscale):
default_colors = OrderedDict(sorted(d.items(), key=lambda t: t[0]))

if colorscale is None:
colorscale = [
rgb_colorscale = [
"rgb(0,116,217)", # blue
"rgb(35,205,205)", # cyan
"rgb(61,153,112)", # green
"rgb(40,35,35)", # black
"rgb(133,20,75)", # magenta
"rgb(255,65,54)", # red
"rgb(255,255,255)", # white
"rgb(255,220,0)",
] # yellow
"rgb(255,220,0)", # yellow
]
else:
rgb_colorscale = colorscale

for i in range(len(default_colors.keys())):
k = list(default_colors.keys())[i] # PY3 won't index keys
if i < len(colorscale):
default_colors[k] = colorscale[i]
if i < len(rgb_colorscale):
default_colors[k] = rgb_colorscale[i]

# add support for cyclic format colors as introduced in scipy===1.5.0
# before this, color_list, from which the color_key is obtained was:
# ['g', 'r', 'b', 'c', 'm', 'b', 'b', 'b', 'b'], now it is
# ['C1', 'C2', 'C0', 'C3', 'C4', 'C0', 'C0', 'C0', 'C0'], so to keep the
# colors consistent regardless of the version of scipy, 'C1' is mapped
# to 'rgb(61,153,112)' (what 'g' was mapped to before), 'C2' is mapped
# to 'rgb(255,65,54)', etc.
cyclic_color_names = ["C%d" % (n,) for n in range(5)]
if colorscale is None:
cyclic_color_rgb = [
"rgb(0,116,217)",
"rgb(61,153,112)",
"rgb(255,65,54)",
"rgb(35,205,205)",
"rgb(133,20,75)",
]
else:
cyclic_color_rgb = colorscale

for k, c in zip(cyclic_color_names, cyclic_color_rgb):
default_colors[k] = c

return default_colors

Expand Down

0 comments on commit 21b38ab

Please sign in to comment.