@@ -424,9 +424,9 @@ def unoverlapped_embedding(G, emb, interaction_edges):
424
424
425
425
426
426
def draw_yield (G , layout , perfect_graph , unused_color = (0.9 ,0.9 ,0.9 ,1.0 ),
427
- fault_color = (1.0 ,0.0 ,0.0 ,1.0 ), fault_shape = 'x ' ,
428
- fault_style = 'dashed' , ** kwargs ):
429
-
427
+ fault_color = (1.0 ,0.0 ,0.0 ,1.0 ), fault_shape = 'o ' ,
428
+ fault_style = 'dashed' , incident_fault_color = ( 1.0 , 0.8 , 0.8 , 1.0 ),
429
+ ** kwargs ):
430
430
"""Draws the given graph G with highlighted faults, according to layout.
431
431
432
432
Parameters
@@ -442,16 +442,19 @@ def draw_yield(G, layout, perfect_graph, unused_color=(0.9,0.9,0.9,1.0),
442
442
perfect_graph : NetworkX graph
443
443
The graph to be drawn with highlighted faults
444
444
445
-
446
445
unused_color : tuple or color string (optional, default (0.9,0.9,0.9,1.0))
447
446
The color to use for nodes and edges of G which are not faults.
448
447
If unused_color is None, these nodes and edges will not be shown at all.
449
448
450
449
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0))
451
- A color to represent nodes absent from the graph G. Colors should be
450
+ A color to represent nodes absent from the graph G, and edges absent
451
+ from the graph G which are not incident to faulty nodes.
452
+
453
+ incident_fault_color : tuple or color string (optional, default (1.0,0.8,0.8,1.0))
454
+ A color to represent edges incident to faulty nodes. Colors should be
452
455
length-4 tuples of floats between 0 and 1 inclusive.
453
456
454
- fault_shape : string, optional (default='x ')
457
+ fault_shape : string, optional (default='o ')
455
458
The shape of the fault nodes. Specification is as matplotlib.scatter
456
459
marker, one of 'so^>v<dph8'.
457
460
@@ -468,37 +471,33 @@ def draw_yield(G, layout, perfect_graph, unused_color=(0.9,0.9,0.9,1.0),
468
471
import matplotlib .pyplot as plt
469
472
import matplotlib as mpl
470
473
except ImportError :
471
- raise ImportError ("Matplotlib and numpy required for draw_chimera ()" )
474
+ raise ImportError ("Matplotlib and numpy required for draw_yield ()" )
472
475
476
+ edgeset = lambda E : set (map (lambda e : tuple (sorted (e )), E ))
473
477
nodelist = G .nodes ()
474
478
edgelist = G .edges ()
479
+
475
480
faults_nodelist = perfect_graph .nodes () - nodelist
476
- faults_edgelist = perfect_graph .edges () - edgelist
481
+ incident_edgelist = edgeset (perfect_graph .edges ) - edgeset (perfect_graph .subgraph (nodelist ).edges )
482
+ faults_edgelist = edgeset (perfect_graph .subgraph (nodelist ).edges ) - edgeset (G .edges )
477
483
478
- # To avoid matplotlib.pyplot.scatter warnings for single tuples, create
479
- # lists of colors from given colors.
480
484
faults_node_color = [fault_color for v in faults_nodelist ]
481
- faults_edge_color = [fault_color for v in faults_edgelist ]
485
+ faults_edge_color = [fault_color for e in faults_edgelist ]
486
+ incident_edge_color = [incident_fault_color for e in incident_edgelist ]
482
487
483
- # Draw faults with different style and shape
484
- draw (perfect_graph , layout , nodelist = faults_nodelist , edgelist = faults_edgelist ,
485
- node_color = faults_node_color , edge_color = faults_edge_color ,
486
- style = fault_style , node_shape = fault_shape ,
487
- ** kwargs )
488
-
489
- # Draw rest of graph
488
+ # Draw edges first, in the order (unused, incident, faults)
490
489
if unused_color is not None :
491
- if nodelist is None :
492
- nodelist = G . nodes () - faults_nodelist
493
- if edgelist is None :
494
- edgelist = G . edges () - faults_edgelist
490
+ unused_edge_color = [ unused_color for e in G . edges ()]
491
+ nx . draw_networkx_edges ( G , layout , edge_color = unused_edge_color , ** kwargs )
492
+ nx . draw_networkx_edges ( perfect_graph , layout , incident_edgelist , style = fault_style , edge_color = incident_edge_color , ** kwargs )
493
+ nx . draw_networkx_edges ( perfect_graph , layout , faults_edgelist , style = fault_style , edge_color = faults_edge_color , ** kwargs )
495
494
496
- unused_node_color = [unused_color for v in nodelist ]
497
- unused_edge_color = [unused_color for v in edgelist ]
495
+ # Draw nodes second, in the order (unused, faults)
496
+ if unused_color is not None :
497
+ unused_node_color = [unused_color for e in G ]
498
+ nx .draw_networkx_nodes (G , layout , node_color = unused_node_color , ** kwargs )
499
+ nx .draw_networkx_nodes (perfect_graph , layout , faults_nodelist , node_shape = fault_shape , node_color = faults_node_color , ** kwargs )
498
500
499
- draw (perfect_graph , layout , nodelist = nodelist , edgelist = edgelist ,
500
- node_color = unused_node_color , edge_color = unused_edge_color ,
501
- ** kwargs )
502
501
503
502
def normalize_size_and_aspect (scale , node_scale , kwargs ):
504
503
ax = kwargs .get ('ax' )
0 commit comments