【问题标题】:How to draw a radial dot image depending on data label in python如何根据python中的数据标签绘制径向点图像
【发布时间】:2021-05-02 21:59:10
【问题描述】:

我想画一个这样的图像,根据数据预测标签

例如,有五个样本 [A,B,C,D,E] 和他们的标签,如 [0,0,0,1,1] 是否有一些现有的包可以在 python 中使用?

另外,我想根据样品的rgb坐标添加颜色,这个包可以完成吗?

【问题讨论】:

    标签: python python-3.x matplotlib


    【解决方案1】:

    您可以使用 networkx 和 matplotlib 来实现这一点。 这是一个最小的例子:

    import networkx as nx
    import matplotlib.pyplot as plt
    
    
    group_a = "group_a"
    group_b = "group_b"
    
    data = list("ABCDE")
    labels = [0, 0, 0, 1, 1]
    
    # create an empty graph
    G = nx.Graph()
    
    G.add_node(group_a)
    G.add_node(group_b)
    
    # add one group or another depending on the label
    for i, label in zip(data, labels):
        if not label:
            target = group_a
        else: 
            target = group_b
            
        G.add_edge(i, target)
    
    
    nx.draw_networkx(G)
    plt.show()
    

    生成以下图像:

    有关更多信息,请参阅Networkx doc

    【讨论】:

    • 如何给每个节点添加颜色?
    猜你喜欢
    • 2014-09-08
    • 2018-01-02
    • 1970-01-01
    • 2021-12-18
    • 2020-01-12
    • 1970-01-01
    • 2017-12-03
    • 2018-11-28
    • 2022-01-21
    相关资源
    最近更新 更多