Added selection of lines in network plot

This commit is contained in:
Arnar Flatberg 2007-02-27 21:19:24 +00:00
parent 78183df0e9
commit 281337251d

View File

@ -6,9 +6,10 @@ from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
from matplotlib.nxutils import points_inside_poly
from matplotlib.figure import Figure
from matplotlib.collections import LineCollection
from matplotlib.patches import Polygon,Rectangle, Circle
from matplotlib.patches import Polygon,Rectangle,Circle
from matplotlib.lines import Line2D
from matplotlib.mlab import prctile
from matplotlib.colors import ColorConverter
import networkx
import scipy
@ -16,7 +17,7 @@ import fluents
import logger
import view
class Plot (view.View):
def __init__(self, title):
view.View.__init__(self, title)
@ -604,7 +605,10 @@ class NetworkPlot(Plot):
self.yaxis_data = self._xy[:,1]
# Initial draw
self.default_props = {'nodesize': 50, 'nodecolor':'gray'}
self.default_props = {'nodesize' : 50,
'nodecolor' : 'gray',
'edge_color' : (.5, .5, .5, 1),
'edge_color_selected' : (1,0,0,1)}
self.node_collection = None
self.edge_collection = None
self.node_labels = None
@ -614,8 +618,9 @@ class NetworkPlot(Plot):
c=self._nodecolor,
linewidth=lw,
zorder=3)
# selected nodes is a transparent graph that adjust edge-visibility
# according to the current selection
# selected nodes is a transparent graph that adjust node-edge visibility
# according to the current selection needed to get get the selected
# nodes 'on top' as zorder may not be defined individually
self.selected_nodes = self.axes.scatter(self.xaxis_data,
self.yaxis_data,
s=self._nodesize,
@ -623,11 +628,16 @@ class NetworkPlot(Plot):
linewidth=lw,
zorder=4,
alpha=0)
edge_color = self.default_props['edge_color']
self.edge_collection = networkx.draw_networkx_edges(self.graph,
self._pos,
ax=self.axes,
edge_color='gray')
edge_color=edge_color)
# edge color rgba-array
self._edge_color_rgba = scipy.repmat(ColorConverter().to_rgba(edge_color),
self.graph.number_of_edges(),1)
self._edge_color_selected = ColorConverter().to_rgba(self.default_props['edge_color_selected'])
if self._with_labels:
self.node_labels = networkx.draw_networkx_labels(self.graph,
self._pos,
@ -665,10 +675,19 @@ class NetworkPlot(Plot):
self.selection_listener(self.current_dim, ids)
def set_current_selection(self, selection):
linewidth = scipy.zeros(self.xaxis_data.shape, 'f')
linewidth = scipy.zeros(self.xaxis_data.shape)
edge_color_rgba = self._edge_color_rgba.copy()
index = self.get_index_from_selection(self.dataset, selection)
if len(index) > 0:
linewidth.put(2, index)
idents = selection[self.current_dim]
edge_index = [i for i,edge in enumerate(self.graph.edges()) if (edge[0] in idents and edge[1] in idents)]
if len(edge_index)>0:
for i in edge_index:
edge_color_rgba[i,:] = self._edge_color_selected
self._A = None
self.edge_collection._colors = edge_color_rgba
self.selected_nodes.set_linewidth(linewidth)
self.canvas.draw()