Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Some adjustements for lineplot

This commit is contained in:
Arnar Flatberg 2006-09-18 17:23:34 +00:00
parent c370d9d250
commit c90f7aabfc
1 changed files with 60 additions and 35 deletions

View File

@ -8,11 +8,13 @@ from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanva
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTK as NavigationToolbar2
from matplotlib.axes import Subplot
from matplotlib.figure import Figure
from matplotlib.numerix import arange, sin, pi
from matplotlib.widgets import RectangleSelector
from matplotlib import cm
from matplotlib import cm,cbook
from pylab import Polygon
from matplotlib.collections import LineCollection
from matplotlib.mlab import prctile
import networkx
from system import logger
from itertools import izip
class ObjectTable:
@ -428,15 +430,39 @@ class LineViewPlot(Plot):
minor_axis = major_axis-1
#initial draw
self.line_collection = {}
x_axis = scipy.arrayrange(self._data.shape[minor_axis])
for i in range(self._data.shape[major_axis]):
yi = self._data.take([i],major_axis)
if self.use_blit:
l,=self.ax.plot(x_axis,yi,'k',alpha=.05,animated=True)
else:
l,=self.ax.plot(x_axis,yi,'k',alpha=.05)
self.line_collection[i] = l
x_axis = scipy.arange(self._data.shape[minor_axis])
self.line_segs=[]
for xi in range(self._data.shape[major_axis]):
yi = self._data.take([xi],major_axis)
self.line_segs.append([(xx,yy) for xx,yy in izip(x_axis,yi)])
#background
xax = scipy.arange(self._data.shape[0])
verts_0 = [] #100,0
verts_1 = [] # 90,10
verts_2 = [] # 75,25
med = []
for i in xax:
pp = prctile(self._data[i,:],[0.,5.,25,50.,75.,95.,100])
verts_0.append((i,pp[0]))
verts_1.append((i,pp[1]))
verts_2.append((i,pp[2]))
for i in xax[::-1]:
pp = prctile(self._data[i,:],[0.,5.,25,50.,75.,95.,100])
verts_0.append((i,pp[-1]))
verts_1.append((i,pp[-2]))
verts_2.append((i,pp[-3]))
med.append(pp[3])
bck0 = Polygon(verts_0,alpha=.15,lw=0)
bck1 = Polygon(verts_1,alpha=.15,lw=0)
bck2 = Polygon(verts_2,alpha=.15,lw=0)
self.ax.add_patch(bck0)
self.ax.add_patch(bck1)
self.ax.add_patch(bck2)
self.ax.plot(xax,med,'b')
self.ax.autoscale_view()
self.add(self.canvas)
self.canvas.show()
@ -463,26 +489,17 @@ class LineViewPlot(Plot):
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
self.canvas.restore_region(self._background)
if index:
if self._last_index:
for i in self._last_index:
# if not using blit: reset last selection
self.ax.lines[i].set_color('k')
self.ax.lines[i].set_alpha(.05)
self.ax.lines[i].set_zorder(1)
for i in index:
self.ax.lines[i].set_color('r')
self.ax.lines[i].set_alpha(1.0)
self.ax.lines[i].set_visible(True)
self.ax.lines[i].set_zorder(3)
if self.use_blit:
self.ax.draw_artist(self.ax.lines[i])
self._last_index = index
if len(index)>0: # do we have a selection
if len(self.ax.collections)>0:
self.ax.collections = []
segs = [self.line_segs[i] for i in index]
line_coll = LineCollection(segs,colors=(1,0,0,1))
if self.use_blit:
self.ax.draw_artist(line_coll)
self.canvas.blit()
else:
self.ax.add_collection(line_coll)
#self.ax.autoscale_view()
self.canvas.draw()
class ScatterMarkerPlot(Plot):
@ -491,8 +508,8 @@ has no color and size options."""
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,s=6, name="Scatter plot"):
Plot.__init__(self, name)
self.ax = self.fig.add_subplot(111)
self.ax.axhline(0,color='k',lw=1.5,zorder=0)
self.ax.axvline(0,color='k',lw=1.5,zorder=0)
self.ax.axhline(0,color='k',lw=1.,zorder=1)
self.ax.axvline(0,color='k',lw=1.,zorder=1)
self.current_dim = id_dim
self.dataset_1 = dataset_1
self.ms = s
@ -558,7 +575,11 @@ has no color and size options."""
self.xaxis_data = dataset_1._array[:,x_index]
self.yaxis_data = dataset_2._array[:,y_index]
lw = scipy.zeros(self.xaxis_data.shape)
self.ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,linewidth=lw,edgecolor='k',alpha=.6,cmap = cm.Set1)
sc = self.ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,linewidth=lw,edgecolor='k',alpha=.6,cmap = cm.jet)
if len(c)>1:
self.fig.colorbar(sc,ticks=[],fraction=.05)
self.ax.axhline(0,color='k',lw=1.,zorder=1)
self.ax.axvline(0,color='k',lw=1.,zorder=1)
self.ax.set_title(self.get_title())
# collection
self.coll = self.ax.collections[0]
@ -594,9 +615,12 @@ has no color and size options."""
def set_current_selection(self, selection):
ids = selection[self.current_dim] # current identifiers
if len(ids)==0:
return
index = self.dataset_1.get_indices(self.current_dim, ids)
lw = scipy.zeros(self.xaxis_data.shape)
scipy.put(lw,index,2.)
if len(index)>0:
lw.put(2.,index)
self.coll.set_linewidth(lw)
self._toolbar.forward() #update data lims before draw
self.canvas.draw()
@ -682,7 +706,8 @@ class NetworkPlot(Plot):
x1, x2 = x2, x1
if y1 > y2:
y1, y2 = y2, y1
index = scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))
index = scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
ids = [node_ids[i] for i in index[0]]
self.selection_listener(self.dataset.get_dim_name(0), ids)