栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python中SciPy树状图的自定义群集颜色(link_color_func?)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python中SciPy树状图的自定义群集颜色(link_color_func?)

这是一个使用返回矩阵

Z
的解决方案
linkage()
(早有描述,但在文档中有所隐藏)和
link_color_func

# see question for pre prior to "color mapping"# Color mappingdflt_col = "#808080"   # Unclustered grayD_leaf_colors = {"attr_1": dflt_col,      "attr_4": "#B061FF", # Cluster 1 indigo      "attr_5": "#B061FF",      "attr_2": "#B061FF",      "attr_8": "#B061FF",      "attr_6": "#B061FF",      "attr_7": "#B061FF",      "attr_0": "#61ffff", # Cluster 2 cyan      "attr_3": "#61ffff",      "attr_9": "#61ffff",      }# notes:# * rows in Z correspond to "inverted U" links that connect clusters# * rows are ordered by increasing distance# * if the colors of the connected clusters match, use that color for linklink_cols = {}for i, i12 in enumerate(Z[:,:2].astype(int)):  c1, c2 = (link_cols[x] if x > len(Z) else D_leaf_colors["attr_%d"%x]    for x in i12)  link_cols[i+1+len(Z)] = c1 if c1 == c2 else dflt_col# DendrogramD = dendrogram(Z=Z, labels=DF_dism.index, color_threshold=None,  leaf_font_size=12, leaf_rotation=45, link_color_func=lambda x: link_cols[x])

这里的输出:



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/626376.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号