added blitting
This commit is contained in:
parent
7940e51867
commit
818cb9f0b7
|
@ -485,7 +485,7 @@ class LineViewPlot(Plot):
|
|||
index = self.dataset.get_indices(self.current_dim, ids)
|
||||
if self.use_blit:
|
||||
if self._background is None:
|
||||
self._last_index = None
|
||||
self._bbox = self.ax.bbox.deepcopy()
|
||||
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||
self.canvas.restore_region(self._background)
|
||||
|
||||
|
@ -494,12 +494,23 @@ class LineViewPlot(Plot):
|
|||
self.ax.collections = []
|
||||
segs = [self.line_segs[i] for i in index]
|
||||
line_coll = LineCollection(segs,colors=(1,0,0,1))
|
||||
line_coll.set_clip_box(self.ax.bbox)
|
||||
self.ax.update_datalim(line_coll.get_verts(self.ax.transData))
|
||||
self._toolbar.forward()
|
||||
if self.use_blit:
|
||||
self.ax.draw_artist(line_coll)
|
||||
#print "\nLine collection clip box:"
|
||||
line_coll.get_clip_box().get_bounds()
|
||||
#print "\nLine collection bbox:"
|
||||
#print self.ax.bbox.get_bounds()
|
||||
#print "Background bbox:"
|
||||
#print self._bbox.get_bounds()
|
||||
#self.canvas.blit(self._bbox)
|
||||
self.canvas.blit()
|
||||
|
||||
#self.ax.draw_artist(line_coll)
|
||||
else:
|
||||
self.ax.add_collection(line_coll)
|
||||
#self.ax.autoscale_view()
|
||||
self.canvas.draw()
|
||||
|
||||
class ScatterMarkerPlot(Plot):
|
||||
|
@ -507,6 +518,8 @@ class ScatterMarkerPlot(Plot):
|
|||
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.use_blit = False
|
||||
self._background = None
|
||||
self.ax = self.fig.add_subplot(111)
|
||||
self.ax.axhline(0,color='k',lw=1.,zorder=1)
|
||||
self.ax.axvline(0,color='k',lw=1.,zorder=1)
|
||||
|
@ -550,6 +563,12 @@ has no color and size options."""
|
|||
def set_current_selection(self, selection):
|
||||
ids = selection[self.current_dim] # current identifiers
|
||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||
if self.use_blit:
|
||||
if self._background is None:
|
||||
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||
self.canvas.restore_region(self._background)
|
||||
if not len(index)>0:
|
||||
return
|
||||
xdata_new = self.xaxis_data.take(index) #take data
|
||||
ydata_new = self.yaxis_data.take(index)
|
||||
#remove old selection
|
||||
|
@ -559,19 +578,26 @@ has no color and size options."""
|
|||
self._selection_line, = self.ax.plot(xdata_new,ydata_new,marker='o',markersize=self.ms,linestyle=None,markerfacecolor='r')
|
||||
|
||||
self._toolbar.forward() #update data lims before draw
|
||||
self.canvas.draw()
|
||||
if self.use_blit:
|
||||
self.ax.draw_artist(self._selection_line)
|
||||
self.canvas.blit()
|
||||
else:
|
||||
self.canvas.draw()
|
||||
|
||||
|
||||
class ScatterPlot(Plot):
|
||||
"""The ScatterMarkerPlot is faster than regular scatterplot, but
|
||||
has no color and size options."""
|
||||
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,c='b',s=30, name="Scatter plot"):
|
||||
"""The ScatterPlot is slower than scattermarker, but has size option."""
|
||||
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,c='b',s=30,sel_dim_2=None, name="Scatter plot"):
|
||||
Plot.__init__(self, name)
|
||||
self.use_blit = False
|
||||
self.ax = self.fig.add_subplot(111)
|
||||
self.current_dim = id_dim
|
||||
self.dataset_1 = dataset_1
|
||||
x_index = dataset_1[sel_dim][id_1]
|
||||
y_index = dataset_2[sel_dim][id_2]
|
||||
if sel_dim_2:
|
||||
y_index = dataset_2[sel_dim_2][id_2]
|
||||
else:
|
||||
y_index = dataset_2[sel_dim][id_2]
|
||||
self.xaxis_data = dataset_1._array[:,x_index]
|
||||
self.yaxis_data = dataset_2._array[:,y_index]
|
||||
lw = scipy.zeros(self.xaxis_data.shape)
|
||||
|
@ -618,12 +644,21 @@ has no color and size options."""
|
|||
if len(ids)==0:
|
||||
return
|
||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||
if self.use_blit:
|
||||
if self._background is None:
|
||||
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||
self.canvas.restore_region(self._background)
|
||||
lw = scipy.zeros(self.xaxis_data.shape)
|
||||
if len(index)>0:
|
||||
lw.put(2.,index)
|
||||
self.coll.set_linewidth(lw)
|
||||
self._toolbar.forward() #update data lims before draw
|
||||
self.canvas.draw()
|
||||
|
||||
if self.use_blit:
|
||||
self.canvas.blit()
|
||||
self.ax.draw_artist(self.coll)
|
||||
else:
|
||||
self.canvas.draw()
|
||||
|
||||
|
||||
class NetworkPlot(Plot):
|
||||
|
@ -709,7 +744,7 @@ class NetworkPlot(Plot):
|
|||
index = scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
|
||||
|
||||
|
||||
ids = [node_ids[i] for i in index[0]]
|
||||
ids = [node_ids[i] for i in index]
|
||||
self.selection_listener(self.dataset.get_dim_name(0), ids)
|
||||
|
||||
def set_current_selection(self, selection):
|
||||
|
|
Reference in New Issue