How to use the networkx.draw_networkx_labels 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 networkit / networkit / src / python / viztools / drawing.py View on Github external
##						alpha=alpha[i])
##				#i += 1
			pass
		else:
			nx.draw_networkx_edges(G, pos, **edgeOpts)

		# draw nodes
		nx.draw_networkx_nodes(G, pos, **self.nodeOpts)
		
		# draw edgelabels
		if weight:
			nx.draw_networkx_edge_labels(G, pos, **edge_labelOpts)
			
		# draw nodelabels
		if self.labelled:
			nx.draw_networkx_labels(G, pos, **self.labelOpts)
github Sung-Huan / ANNOgesic / annogesiclib / plot_PPI.py View on Github external
def nx_label(G, pos, labels, size):
    '''setup the label of network'''
    nx.draw_networkx_labels(G, pos, labels, font_size=size, font_weight='bold')
github ScatterHQ / machinist / spike.py View on Github external
# Yea, just a giant heap of global mutable state.  Why not, anyway?
    draw_networkx_edges(
        graph,
        pos,
        alpha=0.3,
        # width=edgewidth,
        edge_color='m',
    )
    draw_networkx_nodes(
        graph,
        pos,
        # node_size=nodesize,
        node_color='w',
        alpha=0.4,
    )
    draw_networkx_labels(
        graph,
        pos,
    )
    draw_networkx_edge_labels(
        graph,
        pos,
        # This is where things screw up.  get_edge_attributes returns a
        # different data structure for MultiDiGraphs than for DiGraphs.
        # draw_networkx_edge_labels can't deal with the difference.
        edge_labels=get_edge_attributes(graph, "label"),
    )
    # draw_spring(graph)
    font = {
        'fontname'   : 'Helvetica',
        'color'      : 'k',
        'fontweight' : 'bold',
github jcmgray / quimb / quimb / tensor / tensor_core.py View on Github external
# but update with fixed positions
            pos0.update(valmap(lambda xy: np.array(
                (2 * (xy[0] - xymin) / (xymax - xymin) - 1,
                 2 * (xy[1] - xymin) / (xymax - xymin) - 1)), fixed_positions))
            fixed = fixed_positions.keys()
        else:
            fixed = None

        # and then relax remaining using spring layout
        pos = nx.spring_layout(G, pos=pos0, fixed=fixed,
                               k=k, iterations=iterations)

        nx.draw_networkx_nodes(G, pos, node_color=node_colors, node_size=szs,
                               ax=ax, linewidths=node_outline_size,
                               edgecolors=node_outline_colors)
        nx.draw_networkx_labels(G, pos, labels, font_size=10, ax=ax)
        nx.draw_networkx_edges(G, pos, edge_color=edge_colors,
                               alpha=edge_alpha, width=edge_weights, ax=ax)

        # create legend
        if colors and legend:
            handles = []
            for color in colors.values():
                handles += [plt.Line2D([0], [0], marker='o', color=color,
                                       linestyle='', markersize=10)]

            # needed in case '_' is the first character
            lbls = [" {}".format(l) for l in colors]

            plt.legend(handles, lbls, ncol=max(int(len(handles) / 20), 1),
                       loc='center left', bbox_to_anchor=(1, 0.5))
github readdy / readdy / wrappers / python / src / python / readdy / util / topology_utils.py View on Github external
for v in top_graph.get_vertices():
        G.add_node(v.particle_index)
        labels[v.particle_index] = v.label
        if not v.particle_type() in types:
            types[v.particle_type()] = n_types
            n_types += 1
        colors.append(types[v.particle_type()])
    for v in top_graph.get_vertices():
        for vv in v:
            G.add_edge(v.particle_index, vv.get().particle_index)

    pos = nx.spring_layout(G)  # positions for all nodes

    nx.draw_networkx_nodes(G, pos, node_size=700, node_color=colors, cmap=plt.cm.summer)
    nx.draw_networkx_edges(G, pos, width=3)
    nx.draw_networkx_labels(G, pos, font_size=20, labels=labels, font_family='sans-serif')
    plt.show()
github abulka / pynsource / Research / networkx graphs / chess_masters.py View on Github external
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",
        transform=plt.gca().transAxes,
    )
    plt.text(
        0.5,
        0.94,
github nipy / mindboggle / mindboggle / mio / colors.py View on Github external
if plot_graphs:
        plt.figure(nlabels)

        # Graph:
        pos = nx.nx_pydot.graphviz_layout(adjacency_graph, prog="neato")
        nx.draw(adjacency_graph, pos,
                node_color='yellow',
                node_size=graph_node_size,
                width=graph_edge_width,
                with_labels=False)

        # Labels:
        labels={}
        for ilabel in range(nlabels):
            labels[ilabel] = adjacency_graph.node[ilabel]['label']
        nx.draw_networkx_labels(adjacency_graph, pos, labels,
                                font_size=graph_font_size,
                                font_color='black')
        # # Nodes:
        # nodelist = list(adjacency_graph.node.keys())
        # for icolor, new_color in enumerate(new_colors):
        #     nx.draw_networkx_nodes(subgraph, pos,
        #                            node_size=graph_node_size,
        #                            nodelist=[nodelist[icolor]],
        #                            node_color=new_color)

        plt.savefig(graph_image_file)
        plt.show()

    # ------------------------------------------------------------------------
    # Plot the subgraphs (colors):
    # ------------------------------------------------------------------------
github typpo / gilded-age / analyzer / graph.py View on Github external
rgb_blue = (float(numnorth) / total) * 255
            hex_color = '#%02x%02x%02x' % (rgb_red, 0, rgb_blue)

            # Compute size
            size = 80 + total

            # Draw nodes
            nx.draw_networkx_nodes(g, pos, nodelist=[concept], \
                node_color=hex_color, node_size=size, alpha=.8)

        # Draw edges
        nx.draw_networkx_edges(g, pos, edgelist=added_edges)

        # Draw labels
        labels = dict([(x, x) for x in concepts.keys()])
        nx.draw_networkx_labels(g, pos, labels, font_size=8, font_color='green')

        # Draw graph and save
        plt.axis('tight')
        plt.savefig('outputgraph.png')
github arjun-menon / Distributed-Graph-Algorithms / Minimum-Spanning-Tree / tools.py View on Github external
def draw_graph(self, highlighted_edges):
        "Draw graph using_matplotlib"
        import matplotlib
        #if matplotlib.rcParams['backend'] == 'agg':
        matplotlib.rcParams['backend'] = self.backend
        
        import matplotlib.pyplot as plt
        G = self.graph
        
        pos=nx.spring_layout(G, weight = None)
        nx.draw_networkx_nodes(G,pos, node_size=330)
        nx.draw_networkx_edges(G,pos, set(G.edges()) - set(highlighted_edges), width=2)
        nx.draw_networkx_edges(G,pos, highlighted_edges, width=3, edge_color='blue')
        nx.draw_networkx_labels(G,pos, font_size=12, font_family='sans-serif')

        plt.draw()
        plt.show()
github androguard / androguard / androguard / cli / main.py View on Github external
import networkx as nx
    pos = nx.spring_layout(cg)

    internal = []
    external = []

    for n in cg.nodes:
        if n.is_external():
            external.append(n)
        else:
            internal.append(n)

    nx.draw_networkx_nodes(cg, pos=pos, node_color='r', nodelist=internal)
    nx.draw_networkx_nodes(cg, pos=pos, node_color='b', nodelist=external)
    nx.draw_networkx_edges(cg, pos, arrow=True)
    nx.draw_networkx_labels(cg, pos=pos, labels={x: "{}{}".format(x.class_name, x.name) for x in cg.nodes})
    plt.draw()
    plt.show()