diff --git a/laydi/navigator.py b/laydi/navigator.py index f0235be..7053d5f 100644 --- a/laydi/navigator.py +++ b/laydi/navigator.py @@ -255,6 +255,16 @@ class NavigatorMenu(gtk.Menu): self.plot_menu.append(self.plot_line_item) self.plot_line_item.show() + self.plot_bar_item = gtk.MenuItem('Bar Plot') + self.plot_bar_item.connect('activate', self.on_plot_bar, navigator) + self.plot_menu.append(self.plot_bar_item) + self.plot_bar_item.show() + + self.plot_box_item = gtk.MenuItem('Box Plot') + self.plot_box_item.connect('activate', self.on_plot_box, navigator) + self.plot_menu.append(self.plot_box_item) + self.plot_box_item.show() + self.plot_item = gtk.MenuItem('Plot') self.append(self.plot_item) self.plot_item.set_submenu(self.plot_menu) @@ -385,6 +395,28 @@ class NavigatorMenu(gtk.Menu): plot.set_selection_listener(project.set_selection) project._selection_observers.append(plot) + def on_plot_bar(self, item, navigator): + project = main.project + ds = self.dataset + dims = ds.get_dim_name() + ids = ds.get_identifiers(dims[1]) + plot = plots.BarPlot(ds, name='Bar (%s)' % ds.get_name()) + icon = laydi.icon_factory.get("line_plot") + project.data_tree_insert(self.tree_iter, 'Bar plot', plot, None, "black", icon) + plot.set_selection_listener(project.set_selection) + project._selection_observers.append(plot) + + def on_plot_box(self, item, navigator): + project = main.project + ds = self.dataset + dims = ds.get_dim_name() + ids = ds.get_identifiers(dims[1]) + plot = plots.BoxPlot(ds, name='Box (%s)' % ds.get_name()) + icon = laydi.icon_factory.get("line_plot") + project.data_tree_insert(self.tree_iter, 'Box plot', 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() diff --git a/laydi/plots.py b/laydi/plots.py index 1c9b09f..8a264e8 100644 --- a/laydi/plots.py +++ b/laydi/plots.py @@ -756,6 +756,30 @@ class HistogramPlot(Plot): best_bin_size = bin_vec[scipy.argmin(cost)] return best_bin_size +class BoxPlot(Plot): + """Box plot. + """ + def __init__(self, ds, name="Box Plot"): + Plot.__init__(self, name) + + self.axes = self.fig.add_subplot(111) + + m = ds.asarray() + + box_plot_lines = self.axes.boxplot(m) + self.axes.grid(False) + + dim = ds.get_dim_name(1) + labels = ds.get_identifiers(dim, sorted=True) + self.axes.set_xticklabels(labels) + + self.add(self.canvas) + self.canvas.show() + + def set_current_selection(self, selection): + pass + + class BarPlot(Plot): """Bar plot.