LoginSignup
4
1

More than 5 years have passed since last update.

NetworkX と Matplotlib の使い方 (Node の色と大きさ)

Last updated at Posted at 2019-04-18

次のプログラムを改造して Node の色と大きさを変えました。
NetworkX と Matplotlib の使い方

example_sieze01.py
#! /usr/bin/python
#
#   example_size01.py
#
#                       Apr/18/2019
# ------------------------------------------------------------------
import sys
import networkx as nx
import matplotlib
import matplotlib.pyplot as plt
# ------------------------------------------------------------------
def draw_graph(edges):
    G = nx.DiGraph()
    G.add_edges_from(edges)
#
    # Specify the edges you want here
    edge_colours = ['black' for edge in G.edges()]
    black_edges = [edge for edge in G.edges()]

    # Need to create a layout when doing
    # separate calls to draw nodes and edges
    pos = nx.spring_layout(G)
    colors = ["red","green","yellow","blue","magenta"]
    sizes = [1200,1800,2400,3000,3600]
    nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('Reds'), \
        node_color = colors, node_size=sizes)
    nx.draw_networkx_edges(G, pos, edgelist=black_edges, arrows=True)
    nx.draw_networkx_labels(G,pos,font_size=12,font_family='TakaoExMincho')

    plt.axis('off')
    plt.show()
#
# ------------------------------------------------------------------
edges = [('明治','大正'),('大正','昭和'),('昭和','平成'), \
        ('平成','令和'),('令和','明治')]
draw_graph(edges)
# ------------------------------------------------------------------

実行結果
matplot02.png

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1