Skip to content

Commit 344f73c

Browse files
committed
traub 2005 gui: switched to networkx for drawing morphology
The first choice is graphviz twopi for layout. If that does not exist, spectral layout is the best that networkx provides.
1 parent 747bbee commit 344f73c

1 file changed

Lines changed: 6 additions & 36 deletions

File tree

traub_2005/py/gui.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Maintainer:
77
# Created: Fri Jul 12 11:53:50 2013 (+0530)
88
# Version:
9-
# Last-Updated: Thu Aug 11 11:59:17 2016 (-0400)
9+
# Last-Updated: Thu Aug 11 17:21:24 2016 (-0400)
1010
# By: Subhasis Ray
11-
# Update #: 746
11+
# Update #: 781
1212
# URL:
1313
# Keywords:
1414
# Compatibility:
@@ -194,43 +194,13 @@ def displayGraph(self, g, label=False):
194194
if len(sizes) == 0:
195195
print('Empty graph for cell. Make sure proto file has `*asymmetric` on top. I cannot handle symmetric compartmental connections')
196196
return
197-
weights = np.array([g.edge[e[0]][e[1]]['weight'] for e in g.edges()])
198-
try:
199-
pos = nx.graphviz_layout(g, prog='twopi')
200-
except (NameError, AttributeError) as e:
201-
pos = nx.spectral_layout(g)
202-
xmin, ymin, xmax, ymax = 1e9, 1e9, -1e9, -1e9
203-
for p in pos.values():
204-
if xmin > p[0]:
205-
xmin = p[0]
206-
if xmax < p[0]:
207-
xmax = p[0]
208-
if ymin > p[1]:
209-
ymin = p[1]
210-
if ymax < p[1]:
211-
ymax = p[1]
212-
edge_widths = 10.0 * weights / max(weights)
213197
node_colors = ['k' if x in axon else 'gray' for x in g.nodes()]
214198
lw = [1 if n.endswith('comp_1') else 0 for n in g.nodes()]
215-
print('Edge widths:', edge_widths)
216199
self.axes.clear()
217-
self.axes.set_xlim((xmin-10, xmax+10))
218-
self.axes.set_ylim((ymin-10, ymax+10))
219-
for ii, e in enumerate(g.edges()):
220-
p0 = pos[e[0]]
221-
p1 = pos[e[1]]
222-
a = patches.FancyArrow(p0[0], p0[1], p1[0] - p0[0], p1[1] - p0[1], width=edge_widths[ii], head_width=0.0, axes=self.axes, ec='none', fc='black')
223-
self.axes.add_patch(a)
224-
for ii, n in enumerate(g.nodes()):
225-
if n in axon:
226-
ec = 'black'
227-
elif n.endswith('comp_1'):
228-
ec = 'red'
229-
else:
230-
ec = 'none'
231-
c = patches.Circle(pos[n], radius=sizes[ii], axes=self.axes, ec=ec, fc='gray', alpha=0.8)
232-
self.axes.add_patch(c)
233-
self.canvas.draw()
200+
try:
201+
nx.draw_graphviz(g, ax=self.axes, prog='twopi', node_color=node_colors, lw=lw)
202+
except (NameError, AttributeError) as e:
203+
nx.draw_spectral(g, ax=self.axes, node_color=node_colors, lw=lw, with_labels=False, )
234204

235205

236206
class CellView(QtGui.QWidget):

0 commit comments

Comments
 (0)