13
13
from matplotlib .collections import LineCollection
14
14
from matplotlib .patches import FancyArrow
15
15
from matplotlib import pyplot as plt , mpl
16
+ import matplotlib .cbook as cb
16
17
17
18
import networkx as nx
18
19
@@ -483,11 +484,9 @@ def draw_networkx_edges(G, pos,
483
484
try :
484
485
import matplotlib
485
486
import matplotlib .pylab as pylab
486
- import matplotlib .numerix as nmex
487
- import matplotlib .cbook as cb
487
+ import numpy as np
488
488
from matplotlib .colors import colorConverter ,Colormap
489
489
from matplotlib .collections import LineCollection
490
- import matplotlib .numerix .mlab as mlab
491
490
except ImportError :
492
491
raise ImportError , "Matplotlib required for draw()"
493
492
except RuntimeError :
@@ -503,7 +502,7 @@ def draw_networkx_edges(G, pos,
503
502
return None
504
503
505
504
# set edge positions
506
- edge_pos = nmex .asarray ([(pos [e [0 ]],pos [e [1 ]]) for e in edgelist ])
505
+ edge_pos = np .asarray ([(pos [e [0 ]],pos [e [1 ]]) for e in edgelist ])
507
506
508
507
if not cb .iterable (width ):
509
508
lw = (width ,)
@@ -513,16 +512,16 @@ def draw_networkx_edges(G, pos,
513
512
if not cb .is_string_like (edge_color ) \
514
513
and cb .iterable (edge_color ) \
515
514
and len (edge_color )== len (edge_pos ):
516
- if nmex .alltrue ([cb .is_string_like (c )
515
+ if np .alltrue ([cb .is_string_like (c )
517
516
for c in edge_color ]):
518
517
# (should check ALL elements)
519
518
# list of color letters such as ['k','r','k',...]
520
519
edge_colors = tuple ([colorConverter .to_rgba (c ,alpha )
521
520
for c in edge_color ])
522
- elif nmex .alltrue ([not cb .is_string_like (c )
521
+ elif np .alltrue ([not cb .is_string_like (c )
523
522
for c in edge_color ]):
524
523
# If color specs are given as (rgb) or (rgba) tuples, we're OK
525
- if nmex .alltrue ([cb .iterable (c ) and len (c ) in (3 ,4 )
524
+ if np .alltrue ([cb .iterable (c ) and len (c ) in (3 ,4 )
526
525
for c in edge_color ]):
527
526
edge_colors = tuple (edge_color )
528
527
alpha = None
@@ -556,7 +555,7 @@ def draw_networkx_edges(G, pos,
556
555
# just not work with an older mpl
557
556
if edge_colors is None :
558
557
if edge_cmap is not None : assert (isinstance (edge_cmap , Colormap ))
559
- edge_collection .set_array (nmex .asarray (edge_color ))
558
+ edge_collection .set_array (np .asarray (edge_color ))
560
559
edge_collection .set_cmap (edge_cmap )
561
560
if edge_vmin is not None or edge_vmax is not None :
562
561
edge_collection .set_clim (edge_vmin , edge_vmax )
@@ -579,7 +578,7 @@ def draw_networkx_edges(G, pos,
579
578
x2 ,y2 = dst
580
579
dx = x2 - x1 # x offset
581
580
dy = y2 - y1 # y offset
582
- d = nmex .sqrt (float (dx ** 2 + dy ** 2 )) # length of edge
581
+ d = np .sqrt (float (dx ** 2 + dy ** 2 )) # length of edge
583
582
if d == 0 : # source and target at same position
584
583
continue
585
584
if dx == 0 : # vertical edge
@@ -589,9 +588,9 @@ def draw_networkx_edges(G, pos,
589
588
ya = y2
590
589
xa = dx * p + x1
591
590
else :
592
- theta = nmex .arctan2 (dy ,dx )
593
- xa = p * d * nmex .cos (theta )+ x1
594
- ya = p * d * nmex .sin (theta )+ y1
591
+ theta = np .arctan2 (dy ,dx )
592
+ xa = p * d * np .cos (theta )+ x1
593
+ ya = p * d * np .sin (theta )+ y1
595
594
596
595
a_pos .append (((xa ,ya ),(x2 ,y2 )))
597
596
@@ -603,10 +602,10 @@ def draw_networkx_edges(G, pos,
603
602
)
604
603
605
604
# update view
606
- minx = mlab .amin (mlab .ravel (edge_pos [:,:,0 ]))
607
- maxx = mlab .amax (mlab .ravel (edge_pos [:,:,0 ]))
608
- miny = mlab .amin (mlab .ravel (edge_pos [:,:,1 ]))
609
- maxy = mlab .amax (mlab .ravel (edge_pos [:,:,1 ]))
605
+ minx = np .amin (np .ravel (edge_pos [:,:,0 ]))
606
+ maxx = np .amax (np .ravel (edge_pos [:,:,0 ]))
607
+ miny = np .amin (np .ravel (edge_pos [:,:,1 ]))
608
+ maxy = np .amax (np .ravel (edge_pos [:,:,1 ]))
610
609
611
610
w = maxx - minx
612
611
h = maxy - miny
0 commit comments