Added LineViewPLot and renamed ScatterPlot to ScatterMarkerPlot
This commit is contained in:
parent
b14dc3c9c2
commit
8016d732d2
|
@ -381,28 +381,33 @@ class SinePlot(Plot):
|
|||
return self._toolbar
|
||||
|
||||
|
||||
class LinePlot(Plot):
|
||||
def __init__(self, dataset, name="Line plot"):
|
||||
class LineViewPlot(Plot):
|
||||
"""Line view of current selection, no interaction
|
||||
Only works on 2d-arrays
|
||||
input:
|
||||
-- major_axis : dim_number for line dim (see scipy.ndarray for axis def.)
|
||||
-- minor_axis : needs definition only for higher order arrays
|
||||
ps: slow (cant get linecollection and blit to work)
|
||||
"""
|
||||
def __init__(self, dataset,major_axis=1,minor_axis=None, name="Line view"):
|
||||
self._data = dataset.asarray()
|
||||
self.dataset = dataset
|
||||
Plot.__init__(self, name)
|
||||
fig = Figure(figsize=(5,4), dpi=72)
|
||||
self.canvas = FigureCanvas(fig)
|
||||
|
||||
self.ax = ax = fig.add_subplot(111)
|
||||
self._dataset = dataset
|
||||
|
||||
import rpy
|
||||
silent_eval = rpy.with_mode(rpy.NO_CONVERSION, rpy.r)
|
||||
|
||||
rpy.with_mode(rpy.NO_CONVERSION, rpy.r.assign)("m", dataset.asarray())
|
||||
ymin, ymax = rpy.r("range(m)*1.1")
|
||||
self._ymin, self._ymax = ymin, ymax
|
||||
silent_eval("res <- apply(m, 2, density, from=%s, to=%s)" % (ymin, ymax))
|
||||
silent_eval("k <- sapply(1:length(res), function(id) rev(res[[id]]$y))")
|
||||
self._bg_matrix = bg_matrix = rpy.r("k")
|
||||
rpy.r.rm(["k", "res", "m"])
|
||||
|
||||
# Hack - we draw plot in selection_changed()
|
||||
self.selection_changed(None)
|
||||
self.ax = fig.add_subplot(111)
|
||||
self.current_dim = self.dataset.get_dim_name(major_axis)
|
||||
if len(self._data.shape)==2 and not minor_axis:
|
||||
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 = scipy.take(self._data,[i],axis=major_axis)
|
||||
l, = self.ax.plot(x_axis,yi,animated=True)
|
||||
self.line_collection[i] = l
|
||||
# store clean state
|
||||
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||
|
||||
self.add(self.canvas)
|
||||
self.canvas.show()
|
||||
|
@ -412,36 +417,27 @@ class LinePlot(Plot):
|
|||
self._toolbar.set_property('show-arrow', False)
|
||||
|
||||
def get_toolbar(self):
|
||||
self.canvas.draw()
|
||||
return self._toolbar
|
||||
|
||||
def selection_changed(self, selection):
|
||||
self.ax.clear()
|
||||
|
||||
rows, cols = self._bg_matrix.shape
|
||||
self.ax.imshow(self._bg_matrix, cmap=cm.Greys, extent=(0.5, cols+0.5, self._ymin, self._ymax))
|
||||
|
||||
dim_2, dim_1 = self._dataset.get_dim_names()
|
||||
|
||||
if selection:
|
||||
ids = selection[dim_2] # current identifiers
|
||||
index = [ind for id,ind in self._dataset[dim_2].items() if id in ids] #conversion to index
|
||||
ids = selection[self.current_dim] # current identifiers
|
||||
index = self.dataset.get_indices(self.current_dim, ids)
|
||||
if self._background is not None:
|
||||
self.canvas.restore_region(self._background)
|
||||
if index:
|
||||
for i in index:
|
||||
line = self._dataset.asarray()[i]
|
||||
self.ax.plot(range(1, len(line)+1), line)
|
||||
self.line_collection[i].set_visible(True)
|
||||
self.ax.draw_artist(self.line_collection[i])
|
||||
self.canvas.blit()
|
||||
|
||||
self.ax.set_xlim((0.5, cols+0.5))
|
||||
self.ax.set_ylim((self._ymin, self._ymax))
|
||||
self.canvas.draw()
|
||||
|
||||
|
||||
class ScatterPlot(Plot):
|
||||
class ScatterMarkerPlot(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, name="Scatter plot"):
|
||||
Plot.__init__(self, name)
|
||||
fig = Figure(figsize=(5,4), dpi=72)
|
||||
self.ax = ax = fig.add_subplot(111)
|
||||
self.current_dim = id_dim
|
||||
# testing testing
|
||||
self.dataset_1 = dataset_1
|
||||
|
||||
x_index = dataset_1[sel_dim][id_1]
|
||||
|
@ -486,7 +482,6 @@ class ScatterPlot(Plot):
|
|||
|
||||
def selection_changed(self, selection):
|
||||
ids = selection[self.current_dim] # current identifiers
|
||||
|
||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
||||
ydata_new = scipy.take(self.yaxis_data, index)
|
||||
|
|
Reference in New Issue