From edd7d47cf15d807e59eaaefd8f945d4e8421352b Mon Sep 17 00:00:00 2001 From: flatberg Date: Mon, 14 Aug 2006 16:19:51 +0000 Subject: [PATCH] Added regular scatterplot with size and color options --- system/plots.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/system/plots.py b/system/plots.py index d673708..4306f6d 100644 --- a/system/plots.py +++ b/system/plots.py @@ -499,6 +499,65 @@ has no color and size options.""" self._toolbar.forward() #update data lims before draw 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"): + Plot.__init__(self, name) + self.ax = 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] + + self.xaxis_data = dataset_1._array[:,x_index] + self.yaxis_data = dataset_2._array[:,y_index] + + ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,faceted=False,edgecolor='k') + ax.set_title(self.get_title()) + ax.set_xlabel("%s - %s" % (sel_dim, id_1)) + ax.set_ylabel("%s - %s" % (sel_dim, id_2)) + + # collection + self.coll = ax.collections[0] + ### + self.add(self.canvas) + self.canvas.show() + + self._toolbar = NavToolbar(self.canvas, None) + self._toolbar.set_property('show-arrow', False) + self._toolbar.set_select_callback(self.rectangle_select_callback) + + def get_toolbar(self): + return self._toolbar + + def rectangle_select_callback(self, x1, y1, x2, y2): + ydata = self.yaxis_data + xdata = self.xaxis_data + + # find indices of selected area + if x1>x2: + x1, x2 = x2, x1 + if y1>y2: + y1, y2 = y2, y1 + assert x1<=x2 + assert y1<=y2 + + index = scipy.nonzero((xdata>x1) & (xdatay1) & (ydata