How to use the networkx.draw_networkx_nodes function in networkx

To help you get started, we’ve selected a few networkx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liamzebedee / retrust / simulation / graphs.py View on Github external
def draw(G, pos, measures, measure_name):
            # print(list(measures.keys()), list(measures.values()))
            nodes = nx.draw_networkx_nodes(G, pos, node_size=250, cmap=plt.cm.plasma, 
                                        node_color=list(measures.values()),
                                        nodelist=list(measures.keys())  
                                        )
            nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1))
            
            labels = nx.draw_networkx_labels(G, pos, font_color='white')
            edges = nx.draw_networkx_edges(G, pos)

            plt.title(measure_name)
            plt.colorbar(nodes)
            plt.axis('off')
            # plt.show()
            plt.savefig(f'networks/{self.name}.heatmap.png')
github networkx / networkx / examples / multigraph / chess_masters.py View on Github external
wins[u]+=1.0
        elif r[0]=='1/2':
            wins[u]+=0.5
            wins[v]+=0.5
        else:
            wins[v]+=1.0
    try:
        pos=nx.graphviz_layout(H)
    except:
        pos=nx.spring_layout(H,iterations=20)

    plt.rcParams['text.usetex'] = False
    plt.figure(figsize=(8,8))
    nx.draw_networkx_edges(H,pos,alpha=0.3,width=edgewidth, edge_color='m')
    nodesize=[wins[v]*50 for v in H]
    nx.draw_networkx_nodes(H,pos,node_size=nodesize,node_color='w',alpha=0.4)
    nx.draw_networkx_edges(H,pos,alpha=0.4,node_size=0,width=1,edge_color='k')
    nx.draw_networkx_labels(H,pos,fontsize=14)
    font = {'fontname'   : 'Helvetica',
            'color'      : 'k',
            'fontweight' : 'bold',
            'fontsize'   : 14}
    plt.title("World Chess Championship Games: 1886 - 1985", font)

    # change font and write text (using data coordinates)
    font = {'fontname'   : 'Helvetica',
    'color'      : 'r',
    'fontweight' : 'bold',
    'fontsize'   : 14}

    plt.text(0.5, 0.97, "edge width = # games played",
             horizontalalignment='center',
github Sujit-O / pykg2vec / pykg2vec / utils / visualization.py View on Github external
pos[idx] = h_emb[i]
            pos[idx + 1] = r_emb[i]
            pos[idx + 2] = t_emb[i]
            idx += 3

        plt.figure()
        nodes_draw = nx.draw_networkx_nodes(G,
                                            pos,
                                            nodelist=head_nodes,
                                            node_color=head_colors,
                                            node_shape='o',
                                            node_size=50)
        nodes_draw.set_edgecolor('k')

        nodes_draw = nx.draw_networkx_nodes(G,
                                            pos,
                                            nodelist=rel_nodes,
                                            node_color=rel_colors,
                                            node_size=50,
                                            node_shape='D',
                                            with_labels=show_label)
        nodes_draw.set_edgecolor('k')

        nodes_draw = nx.draw_networkx_nodes(G,
                                            pos,
                                            nodelist=tail_nodes,
                                            node_color=tail_colors,
                                            node_shape='*',
                                            node_size=50)
        nodes_draw.set_edgecolor('k')
github sujitpal / hia-examples / scala / cms-disease-graph / src / main / python / disease_graph.py View on Github external
edge_color='blue', edge_alpha=0.3, edge_tickness=1,
               edge_text_pos=0.3,
               text_font='sans-serif'):

    # these are different layouts for the network you may try
    # shell seems to work best
    if graph_layout == 'spring':
        graph_pos=nx.spring_layout(G)
    elif graph_layout == 'spectral':
        graph_pos=nx.spectral_layout(G)
    elif graph_layout == 'random':
        graph_pos=nx.random_layout(G)
    else:
        graph_pos=nx.shell_layout(G)
    # draw graph
    nx.draw_networkx_nodes(G,graph_pos,node_size=node_size, 
                           alpha=node_alpha, node_color=node_color)
    nx.draw_networkx_edges(G,graph_pos,width=edge_tickness,
                           alpha=edge_alpha,edge_color=edge_color)
    nx.draw_networkx_labels(G, graph_pos,font_size=node_text_size,
                            font_family=text_font)
    nx.draw_networkx_edge_labels(G, graph_pos, edge_labels=labels, 
                                 label_pos=edge_text_pos)
    # show graph
    frame = plt.gca()
    plt.gcf().set_size_inches(10, 10)
    frame.axes.get_xaxis().set_visible(False)
    frame.axes.get_yaxis().set_visible(False)

    plt.show()
github SkBlaz / Py3plex / build / lib / py3plex / visualization / multilayer.py View on Github external
## standard force -- directed layout
    if layout_algorithm == "force":
        pos = compute_force_directed_layout(g,layout_parameters)

    ## random layout -- used for initialization of more complex algorithms
    elif layout_algorithm == "random":
        pos = compute_random_layout(g)

    elif layout_algorithm == "custom_coordinates":
        pos = layout_parameters['pos']
        
    else:
        pos = compute_force_directed_layout(g,layout_parameters)

    ec = nx.draw_networkx_edges(g, pos, alpha=0.85,edge_color="black", width=0.1,arrows=False)
    nc = nx.draw_networkx_nodes(g, pos, nodelist=[n1[0] for n1 in nodes], node_color=final_color_mapping,with_labels=False, node_size=nsizes)
    plt.axis('off')

    ## add legend
    markers = [plt.Line2D([0,0],[0,0], color=color_mapping[item], marker='o', linestyle='') for item in list(unique_colors)]
    
    if legend:
        plt.legend(markers, list(unique_colors), numpoints=1,fontsize = 'medium')
    
    if display:
        plt.show()
github Patent2net / Patent2Net--Old-stuff / Development / networkx_functs.py View on Github external
def draw_partition(graph, partition):
    ''' Requires matplotlib.pyplot, uncomment in the top imports if you want
    to try this, but it's a useless hairy graph for the infovis data.
    Uses community code and sample from http://perso.crans.org/aynaud/communities/ to draw matplotlib graph in shades of gray
    '''
    g = graph
    count = 0
    size = float(len(set(partition.values())))
    pos = nx.spring_layout(g)
    for com in set(partition.values()):
        count = count + 1
        list_nodes = [nodes for nodes in partition.keys()
                                    if partition[nodes] == com]
        nx.draw_networkx_nodes(g, pos, list_nodes, node_size = 20,
                                    node_color = str(count / size))
    nx.draw_networkx_edges(g,pos, alpha=0.5)
    plt.show()
github nelpy / nelpy / nelpy / plotting / graph.py View on Github external
edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]
    edgewidth = np.array(edgewidth)
    edgewidth[edgewidth
github esa / pagmo / PyGMO / problem / _tsp.py View on Github external
pos[i][1] = omega * pos[i][1]  # orient node
                # We have to check the distance to all the previous
                # nodes to decide if the problem is euclidian
                for j in range(2, i):
                    if abs(((pos[i][0] - pos[j][0]) ** 2 +
                           (pos[i][1] - pos[j][1]) ** 2) ** (0.5) -
                       weights[i][j]) > 1e-08 * weights[i][j]:
                        prob_is_eucl = False
            i += 1
        # In case of a non euclidian TSP we create a spring model
        if prob_is_eucl is False:
            pos = nx.layout.spring_layout(G)
    if node_color is None:
        node_color = [0.4] * n_cities

    nx.draw_networkx_nodes(G, pos=pos, node_size=node_size,
                           cmap=plt.cm.Blues, node_color=node_color, ax=axis)
    nx.draw_networkx_edges(G, pos, edgelist=edgelist,
                           width=edge_width, alpha=1, edge_color=edge_color, ax=axis)
    fig.canvas.draw()
    plt.show()
    return pos
github esa / pagmo / PyGMO / core / __init__.py View on Github external
m = min(node_colors)

    else:
        node_colors = n_color
        m = 0
        M = 0

    if not m == M:
        node_colors = [(node_colors[i] - float(m)) / (M - m)
                       for i in range(len(self))]

    # And we draw the archipelago .....
    ax = pl.figure()
    if cmap == 'default':
        cmap = pl.cm.Reds_r
    nx.draw_networkx_nodes(
        G,
        pos,
        nodelist=list(
            range(
                len(self))),
        node_color=node_colors,
        cmap=cmap,
        node_size=node_sizes,
        alpha=n_alpha)
    nx.draw_networkx_edges(G, pos, alpha=e_alpha, arrows=e_arrows)
    pl.axis('off')
    pl.show()
    return pos
archipelago.draw = _archipelago_draw
github SimonStreicher / FaultMap / ranking / visualise.py View on Github external
self.G2 = self.G.copy()
            print(pairingpattern)
            self.G2.add_edges_from(self.G2.edges(), edgecolour='k')
            self.G2.add_edges_from(pairingpattern, edgecolour='r')
        #correct up to here
            pairingtuplelist = [(row[0], row[1]) for row in pairingpattern] #what a mission to find this error
            edgecolorlist = ["r" if edge in pairingtuplelist else "k" for edge in self.G2.edges()]


            if nodepositions == None:
                nodepositions = nx.circular_layout(self.G2)

            plt.figure(message)
            nx.draw_networkx(self.G2, pos=nodepositions)
            nx.draw_networkx_edges(self.G2, pos=nodepositions, width=2.5, edge_color=edgecolorlist, style='solid', alpha=0.5)
            nx.draw_networkx_nodes(self.G2, pos=nodepositions, node_color='y', node_size=450)
            plt.axis('off')