Beispiel #1
0
def draw_simple(graph,layout='circular',
                vertexid_aslabel=False,
                edgeweight_aslabel=False,
                vlabel='',v_attrs={},elabel='',e_attrs={},
                vertex_color='blue',
                edge_color='black',
                vertex_font_color='white',
                edge_font_color='gray',
                axis=True,
                width=8,
                height=5,
                vsize=450,
                cmap=None):
  
  vertex_labels = {}
  if(vlabel!='' and v_attrs!={}):
    for v in graph.vertices:
      if vlabel in v_attrs[v].keys():
        vertex_labels[v] = v_attrs[v][vlabel]
  elif vertexid_aslabel:
    for v in graph.vertices:
      vertex_labels[v] = str(v)
  edge_labels = {}
  if(elabel!='' and e_attrs!={}):
    for e in graph.edges:
      if elabel in e_attrs[e].keys():
        edge_labels[e] = e_attrs[e][elabel]
  elif edgeweight_aslabel:
    for e in graph.edges:
      edge_labels[e] = str(graph.get_edge_weight(e))
  positions = draw_matplotlib.layout(graph, seed=10, name=layout)
  draw_matplotlib.draw_jgrapht(
    graph,
    positions=positions,
    vertex_color=vertex_color,
    edge_color=edge_color,
    edge_linewidth=1,
    vertex_labels=vertex_labels,
    vertex_font_color=vertex_font_color,
    edge_labels=edge_labels,
    edge_font_color=edge_font_color,
    axis=axis,
    vertex_size=vsize,
    vertex_cmap=cmap
  )
  plt.rcParams['figure.figsize'] = [width,height]
  plt.show()
e1 = g.add_edge(0, 1)
e2 = g.add_edge(0, 2)
e3 = g.add_edge(0, 3)
e4 = g.add_edge(0, 4)
e5 = g.add_edge(0, 5)
e6 = g.add_edge(0, 6)
e7 = g.add_edge(0, 7)
e8 = g.add_edge(0, 8)
e9 = g.add_edge(0, 9)

# %%
# Compute the position of the vertices
positions = drawing.layout(g, seed=10, name="circular")

# %%
# Draw the graph using the node labels,arrows,node colormap,arrow line,arrow color,connection style and edge line width
drawing.draw_jgrapht(
    g,
    positions=positions,
    node_label=True,
    node_color=range(len(g.vertices)),
    node_cmap=plt.cm.Blues,
    edge_linewidth=4,
    arrow=True,
    arrow_color="orange",
    arrow_line="dotted",
    connection_style="arc3,rad=-0.3",
    axis=False,
)
plt.show()

# %%
# and some edges
e1 = g.add_edge(0, 1)
e2 = g.add_edge(0, 2)
e3 = g.add_edge(0, 3)
e4 = g.add_edge(0, 4)
e5 = g.add_edge(0, 5)
e6 = g.add_edge(0, 6)
e7 = g.add_edge(0, 7)
e8 = g.add_edge(0, 8)
e9 = g.add_edge(0, 9)

# %%
# Compute the position of the vertices
positions = draw_matplotlib.layout(g, name="circular")

# %%
# Draw the graph using the vertex labels, edge labels and vertex colormap
draw_matplotlib.draw_jgrapht(
    g,
    positions=positions,
    vertex_labels={v: v for v in g.vertices},
    edge_labels={e: e for e in g.edges},
    vertex_color=range(len(g.vertices)),
    vertex_cmap=plt.cm.Oranges,
    axis=False,
)
plt.show()
for i in range(0, 10):
    g.add_vertex()

# %%
# and some edges

e1 = g.add_edge(0, 1)
e2 = g.add_edge(0, 2)
e3 = g.add_edge(0, 3)
e4 = g.add_edge(0, 4)
e5 = g.add_edge(0, 5)
e6 = g.add_edge(0, 6)
e7 = g.add_edge(0, 7)
e8 = g.add_edge(0, 8)
e9 = g.add_edge(0, 9)

# %%
# Compute the position of the vertices
positions = drawing.layout(g, name="circular")
# %%
# Draw the graph using the node labels and the edge line width and edge colormap
drawing.draw_jgrapht(
    g,
    positions=positions,
    edge_linewidth=6,
    edge_cmap=plt.cm.Blues(np.linspace(0.1, 1, len(g.edges))),
    axis=False,
)
plt.show()
    g.add_vertex()

# %%
# and some edges

e1 = g.add_edge(0, 1)
e2 = g.add_edge(0, 2)
e3 = g.add_edge(0, 3)
e4 = g.add_edge(0, 4)
e5 = g.add_edge(0, 5)
e6 = g.add_edge(0, 6)
e7 = g.add_edge(0, 7)
e8 = g.add_edge(0, 8)
e9 = g.add_edge(0, 9)
e10 = g.add_edge(1, 2)

# %%
# Compute the position of the vertices
positions = drawing.layout(g, seed=10, name="fruchterman_reingold")

# %%
# Draw the graph using the vertex labels and the edge labels
vertex_labels = {v: v for v in g.vertices}
edge_labels = {e: e for e in g.edges}
drawing.draw_jgrapht(g,
                     position=positions,
                     vertex_labels=vertex_labels,
                     edge_labels=edge_labels,
                     axis=False)
plt.show()