Added scatter plotting from dataset in navigator.
This commit is contained in:
parent
aef2e1daf0
commit
7ee7f0cf7e
|
@ -235,6 +235,11 @@ class NavigatorMenu(gtk.Menu):
|
|||
self.plot_menu.append(self.plot_hist_item)
|
||||
self.plot_hist_item.show()
|
||||
|
||||
self.plot_scatter_item = gtk.MenuItem('Scatter')
|
||||
self.plot_scatter_item.connect('activate', self.on_plot_scatter, navigator)
|
||||
self.plot_menu.append(self.plot_scatter_item)
|
||||
self.plot_scatter_item.show()
|
||||
|
||||
self.plot_item = gtk.MenuItem('Plot')
|
||||
self.append(self.plot_item)
|
||||
self.plot_item.set_submenu(self.plot_menu)
|
||||
|
@ -314,6 +319,21 @@ class NavigatorMenu(gtk.Menu):
|
|||
plot.set_selection_listener(project.set_selection)
|
||||
project._selection_observers.append(plot)
|
||||
|
||||
def on_plot_scatter(self, item, navigator):
|
||||
project = main.project
|
||||
ds = self.dataset
|
||||
dims = ds.get_dim_name()
|
||||
ids = ds.get_identifiers(dims[1])
|
||||
plot = plots.ScatterPlot(ds, ds,
|
||||
dims[0], dims[1],
|
||||
ids[0], ids[1],
|
||||
name='Scatter (%s)' % ds.get_name())
|
||||
plot.add_axes_spin_buttons(len(ids), 0, 1)
|
||||
icon = fluents.icon_factory.get("line_plot")
|
||||
project.data_tree_insert(self.tree_iter, 'Scatter', plot, None, "black", icon)
|
||||
plot.set_selection_listener(project.set_selection)
|
||||
project._selection_observers.append(plot)
|
||||
|
||||
def on_transpose(self, item, navigator):
|
||||
project = main.project
|
||||
ds = self.dataset.transpose()
|
||||
|
|
|
@ -401,7 +401,63 @@ class ScatterPlot(Plot):
|
|||
self.connect('pan-changed', self.onpan)
|
||||
self.need_redraw = False
|
||||
self.canvas.mpl_connect('resize_event', self.onresize)
|
||||
|
||||
def add_axes_spin_buttons(self, max=None, absi=0, ordi=1):
|
||||
self._absi = absi
|
||||
self._ordi = ordi
|
||||
if max == None:
|
||||
max=5
|
||||
sb_a = gtk.SpinButton(climb_rate=1)
|
||||
sb_a.set_range(1, max)
|
||||
sb_a.set_value(absi+1)
|
||||
sb_a.set_increments(1, 5)
|
||||
sb_a.connect('value_changed', self.set_absicca)
|
||||
sb_o = gtk.SpinButton(climb_rate=1)
|
||||
sb_o.set_range(1, max)
|
||||
sb_o.set_value(ordi+1)
|
||||
sb_o.set_increments(1, 5)
|
||||
sb_o.connect('value_changed', self.set_ordinate)
|
||||
hbox = gtk.HBox()
|
||||
gtk_label_a = gtk.Label("A:")
|
||||
gtk_label_o = gtk.Label(" O:")
|
||||
toolitem = gtk.ToolItem()
|
||||
toolitem.set_expand(False)
|
||||
toolitem.set_border_width(2)
|
||||
toolitem.add(hbox)
|
||||
hbox.pack_start(gtk_label_a)
|
||||
hbox.pack_start(sb_a)
|
||||
hbox.pack_start(gtk_label_o)
|
||||
hbox.pack_start(sb_o)
|
||||
self._toolbar.insert(toolitem, -1)
|
||||
toolitem.set_tooltip(self._toolbar.tooltips, "Set Principal component")
|
||||
self._toolbar.show_all() #do i need this?
|
||||
|
||||
def set_absicca(self, sb):
|
||||
self._absi = sb.get_value_as_int() - 1
|
||||
xy = self.dataset_1._array[:,[self._absi, self._ordi]]
|
||||
self.xaxis_data = xy[:,0]
|
||||
self.yaxis_data = xy[:,1]
|
||||
self.sc._offsets = xy
|
||||
self.selection_collection._offsets = xy
|
||||
self.canvas.draw_idle()
|
||||
pad = abs(self.xaxis_data.min()-self.xaxis_data.max())*0.05
|
||||
new_lims = (self.xaxis_data.min() - pad, self.xaxis_data.max() + pad)
|
||||
self.axes.set_xlim(new_lims, emit=True)
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def set_ordinate(self, sb):
|
||||
self._ordi = sb.get_value_as_int() - 1
|
||||
xy = self.dataset_1._array[:,[self._absi, self._ordi]]
|
||||
#xy = self._T[:,[self._absi, self._ordi]]
|
||||
self.xaxis_data = xy[:,0]
|
||||
self.yaxis_data = xy[:,1]
|
||||
self.sc._offsets = xy
|
||||
self.selection_collection._offsets = xy
|
||||
pad = abs(self.yaxis_data.min()-self.yaxis_data.max())*0.05
|
||||
new_lims = (self.yaxis_data.min() - pad, self.yaxis_data.max() + pad)
|
||||
self.axes.set_ylim(new_lims, emit=True)
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def onzoom(self, widget, mode):
|
||||
#logger.log('notice', 'Zoom in widget: %s' %widget)
|
||||
self.clean_redraw()
|
||||
|
|
Reference in New Issue