Added regular scatterplot with size and color options

This commit is contained in:
Arnar Flatberg 2006-08-14 16:19:51 +00:00
parent a5c5987fc3
commit edd7d47cf1

View File

@ -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) & (xdata<x2) & (ydata>y1) & (ydata<y2))
ids = self.dataset_1.get_identifiers(self.current_dim, index)
self.selection_listener(self.current_dim, ids)
def selection_changed(self, selection):
ids = selection[self.current_dim] # current identifiers
index = self.dataset_1.get_indices(self.current_dim, ids)
lw = scipy.zeros(self.xaxis_data.shape,'f')
scipy.put(lw,index,2.)
self.coll.set_linewidth(lw)
self._toolbar.forward() #update data lims before draw
self.canvas.draw()
class NetworkPlot(Plot):
def __init__(self, dataset, **kw):
# Set member variables and call superclass' constructor