Skip to content

Commit 31cf4f5

Browse files
committed
Merge pull request #1 from cindeem/small_updates
Small import updates in nxplot.
2 parents 845a3e8 + 5f91dee commit 31cf4f5

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

brainx/nxplot.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from matplotlib.collections import LineCollection
1414
from matplotlib.patches import FancyArrow
1515
from matplotlib import pyplot as plt, mpl
16+
import matplotlib.cbook as cb
1617

1718
import networkx as nx
1819

@@ -483,11 +484,9 @@ def draw_networkx_edges(G, pos,
483484
try:
484485
import matplotlib
485486
import matplotlib.pylab as pylab
486-
import matplotlib.numerix as nmex
487-
import matplotlib.cbook as cb
487+
import numpy as np
488488
from matplotlib.colors import colorConverter,Colormap
489489
from matplotlib.collections import LineCollection
490-
import matplotlib.numerix.mlab as mlab
491490
except ImportError:
492491
raise ImportError, "Matplotlib required for draw()"
493492
except RuntimeError:
@@ -503,7 +502,7 @@ def draw_networkx_edges(G, pos,
503502
return None
504503

505504
# 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])
507506

508507
if not cb.iterable(width):
509508
lw = (width,)
@@ -513,16 +512,16 @@ def draw_networkx_edges(G, pos,
513512
if not cb.is_string_like(edge_color) \
514513
and cb.iterable(edge_color) \
515514
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)
517516
for c in edge_color]):
518517
# (should check ALL elements)
519518
# list of color letters such as ['k','r','k',...]
520519
edge_colors = tuple([colorConverter.to_rgba(c,alpha)
521520
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)
523522
for c in edge_color]):
524523
# 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)
526525
for c in edge_color]):
527526
edge_colors = tuple(edge_color)
528527
alpha=None
@@ -556,7 +555,7 @@ def draw_networkx_edges(G, pos,
556555
# just not work with an older mpl
557556
if edge_colors is None:
558557
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))
560559
edge_collection.set_cmap(edge_cmap)
561560
if edge_vmin is not None or edge_vmax is not None:
562561
edge_collection.set_clim(edge_vmin, edge_vmax)
@@ -579,7 +578,7 @@ def draw_networkx_edges(G, pos,
579578
x2,y2=dst
580579
dx=x2-x1 # x offset
581580
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
583582
if d==0: # source and target at same position
584583
continue
585584
if dx==0: # vertical edge
@@ -589,9 +588,9 @@ def draw_networkx_edges(G, pos,
589588
ya=y2
590589
xa=dx*p+x1
591590
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
595594

596595
a_pos.append(((xa,ya),(x2,y2)))
597596

@@ -603,10 +602,10 @@ def draw_networkx_edges(G, pos,
603602
)
604603

605604
# 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]))
610609

611610
w = maxx-minx
612611
h = maxy-miny

0 commit comments

Comments
 (0)