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
|
return self._toolbar
|
||||||
|
|
||||||
|
|
||||||
class LinePlot(Plot):
|
class LineViewPlot(Plot):
|
||||||
def __init__(self, dataset, name="Line 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)
|
Plot.__init__(self, name)
|
||||||
fig = Figure(figsize=(5,4), dpi=72)
|
fig = Figure(figsize=(5,4), dpi=72)
|
||||||
self.canvas = FigureCanvas(fig)
|
self.canvas = FigureCanvas(fig)
|
||||||
|
self.ax = fig.add_subplot(111)
|
||||||
self.ax = ax = fig.add_subplot(111)
|
self.current_dim = self.dataset.get_dim_name(major_axis)
|
||||||
self._dataset = dataset
|
if len(self._data.shape)==2 and not minor_axis:
|
||||||
|
minor_axis = major_axis-1
|
||||||
import rpy
|
#initial draw
|
||||||
silent_eval = rpy.with_mode(rpy.NO_CONVERSION, rpy.r)
|
self.line_collection = {}
|
||||||
|
x_axis = scipy.arrayrange(self._data.shape[minor_axis])
|
||||||
rpy.with_mode(rpy.NO_CONVERSION, rpy.r.assign)("m", dataset.asarray())
|
for i in range(self._data.shape[major_axis]):
|
||||||
ymin, ymax = rpy.r("range(m)*1.1")
|
yi = scipy.take(self._data,[i],axis=major_axis)
|
||||||
self._ymin, self._ymax = ymin, ymax
|
l, = self.ax.plot(x_axis,yi,animated=True)
|
||||||
silent_eval("res <- apply(m, 2, density, from=%s, to=%s)" % (ymin, ymax))
|
self.line_collection[i] = l
|
||||||
silent_eval("k <- sapply(1:length(res), function(id) rev(res[[id]]$y))")
|
# store clean state
|
||||||
self._bg_matrix = bg_matrix = rpy.r("k")
|
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||||
rpy.r.rm(["k", "res", "m"])
|
|
||||||
|
|
||||||
# Hack - we draw plot in selection_changed()
|
|
||||||
self.selection_changed(None)
|
|
||||||
|
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
self.canvas.show()
|
self.canvas.show()
|
||||||
|
@ -412,36 +417,27 @@ class LinePlot(Plot):
|
||||||
self._toolbar.set_property('show-arrow', False)
|
self._toolbar.set_property('show-arrow', False)
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
self.canvas.draw()
|
|
||||||
return self._toolbar
|
return self._toolbar
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, selection):
|
||||||
self.ax.clear()
|
ids = selection[self.current_dim] # current identifiers
|
||||||
|
index = self.dataset.get_indices(self.current_dim, ids)
|
||||||
rows, cols = self._bg_matrix.shape
|
if self._background is not None:
|
||||||
self.ax.imshow(self._bg_matrix, cmap=cm.Greys, extent=(0.5, cols+0.5, self._ymin, self._ymax))
|
self.canvas.restore_region(self._background)
|
||||||
|
if index:
|
||||||
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
|
|
||||||
for i in index:
|
for i in index:
|
||||||
line = self._dataset.asarray()[i]
|
self.line_collection[i].set_visible(True)
|
||||||
self.ax.plot(range(1, len(line)+1), line)
|
self.ax.draw_artist(self.line_collection[i])
|
||||||
|
self.canvas.blit()
|
||||||
|
|
||||||
self.ax.set_xlim((0.5, cols+0.5))
|
class ScatterMarkerPlot(Plot):
|
||||||
self.ax.set_ylim((self._ymin, self._ymax))
|
"""The ScatterMarkerPlot is faster than regular scatterplot, but
|
||||||
self.canvas.draw()
|
has no color and size options."""
|
||||||
|
|
||||||
|
|
||||||
class ScatterPlot(Plot):
|
|
||||||
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2, name="Scatter plot"):
|
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2, name="Scatter plot"):
|
||||||
Plot.__init__(self, name)
|
Plot.__init__(self, name)
|
||||||
fig = Figure(figsize=(5,4), dpi=72)
|
fig = Figure(figsize=(5,4), dpi=72)
|
||||||
self.ax = ax = fig.add_subplot(111)
|
self.ax = ax = fig.add_subplot(111)
|
||||||
self.current_dim = id_dim
|
self.current_dim = id_dim
|
||||||
# testing testing
|
|
||||||
self.dataset_1 = dataset_1
|
self.dataset_1 = dataset_1
|
||||||
|
|
||||||
x_index = dataset_1[sel_dim][id_1]
|
x_index = dataset_1[sel_dim][id_1]
|
||||||
|
@ -486,7 +482,6 @@ class ScatterPlot(Plot):
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, selection):
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
|
|
||||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||||
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
||||||
ydata_new = scipy.take(self.yaxis_data, index)
|
ydata_new = scipy.take(self.yaxis_data, index)
|
||||||
|
|
Reference in New Issue