def add_eics(self, data, labels=None, configs=None): """ do not forget to call replot() after calling this function ! """ allrts = list() if configs is None: configs = [{"color": getColor(i)} for i in range(len(data))] if labels is None: labels = [""] * len(data) unique_labels = set() # items_with_label = [] seen = set() for i, (rts, chromatogram) in enumerate(data): # we do not plot duplicates, which might happen if multiple lines in the # table explorer are sellected ! if (id(rts), id(chromatogram)) in seen: continue seen.add((id(rts), id(chromatogram))) config = configs[i] label = "<pre>%s</pre>" % labels[i] unique_labels.add(label) curve = make_unselectable_curve(rts, chromatogram, title=label, **config) allrts.extend(rts) self.plot.add_item(curve) self.plot.add_item(self.label) self.plot.set_x_values(sorted(set(allrts))) # no idea why guiqwt needs double registration here: self.marker.attach(self.plot) self.plot.add_item(self.marker) # self._add_legend(unique_labels, items_with_label) if self.range_ is not None: self.plot.add_item(self.range_)
def __init__(self, parent=None): super(MzPlottingWidget, self).__init__(parent, xlabel="mz", ylabel="I") patch_inner_plot_object(self, MzPlot) self.plot.centralMz = None def label(self, x): # label with full precision: return QwtText(str(x)) a = QwtScaleDraw() a.label = new.instancemethod(label, self.plot, QwtScaleDraw) self.plot.setAxisScaleDraw(self.plot.xBottom, a) self.pm = PlotManager(self) self.pm.add_plot(self.plot) self.curve = make_unselectable_curve([], [], color="b", curvestyle="Sticks") self.plot.add_item(self.curve) t = self.pm.add_tool(MzSelectionTool) self.pm.set_default_tool(t) t.activate() marker = Marker(label_cb=self.plot.label_info, constraint_cb=self.plot.on_plot) marker.attach(self.plot) line = make_measurement_line() line.setVisible(0) setupCommonStyle(line, marker) line.shapeparam.line.color = "#555555" line.shapeparam.update_shape(line) label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None) label.labelparam.label = "" label.labelparam.font.size = 12 label.labelparam.update_label(label) self.marker = marker self.label = label self.line = line
def add_time_series(self, time_series, configs=None): seen = set() x_values = [] labels = [] items_with_label = [] for i, ts in enumerate(time_series): # we do not plot duplicates, which might happen if multiple lines in the # table explorer are sellected ! if ts.uniqueId() in seen: continue seen.add(ts.uniqueId()) config = None if configs is not None: config = configs[i] if config is None: config = dict(color=getColor(i)) title = ts.label for j, item in enumerate(ts.for_plotting()): lconfig = config.copy() if len(item) == 2: x, y = item else: x, y, special_config = item lconfig.update(special_config) x = [ xi.toordinal() if isinstance(xi, datetime) else xi for xi in x ] x_values.extend(x) curve = make_unselectable_curve(x, y, title="<pre>%s</pre>" % title, **lconfig) self.plot.add_item(curve) if j == 0: labels.append(title) items_with_label.append(curve) x_values = sorted(set(x_values)) self.plot.set_x_values(x_values) self.plot.add_item(self.marker) self.plot.add_item(self.label) unique_labels = set(labels) self._add_legend(unique_labels, items_with_label)
def plot_spectra(self, all_peaks, labels): self.plot.del_all_items() self.plot.add_item(self.marker) self.plot.add_item(make.legend("TL")) self.plot.add_item(self.label) for i, (peaks, label) in enumerate(zip(all_peaks, labels)): config = dict(color=getColor(i)) curve = make_unselectable_curve([], [], title=label, curvestyle="Sticks", **config) curve.set_data(peaks[:, 0], peaks[:, 1]) self.plot.add_item(curve) self.plot.resample_config = [] self.plot.add_item(self.line) if len(all_peaks): self.plot.all_peaks = np.vstack(all_peaks) else: self.plot.all_peaks = np.zeros((0, 2))
def eic_plotter(self): """generator which receives plot items""" unique_labels = set() seen = set() allrts = [] for i in itertools.count(): item = yield if item is None: break label, curve, config = item if config is None: config = {"color": getColor(i), "linewidth": 1.5} rts, chromatogram = curve if (id(rts), id(chromatogram)) in seen: continue seen.add((id(rts), id(chromatogram))) label = "<pre>%s</pre>" % label unique_labels.add(label) curve = make_unselectable_curve(rts, chromatogram, title=label, **config) allrts.extend(rts) self.plot.add_item(curve) self.plot.replot() qapplication().processEvents() self.plot.add_item(self.label) self.plot.set_x_values(sorted(set(allrts))) # no idea why guiqwt needs double registration here: self.marker.attach(self.plot) self.plot.add_item(self.marker) if self.range_ is not None: self.plot.add_item(self.range_) self.plot.replot() yield # avoids StopIteration
def add_time_series(self, time_series, configs=None): seen = set() x_values = [] labels = [] items_with_label = [] for i, ts in enumerate(time_series): # we do not plot duplicates, which might happen if multiple lines in the # table explorer are sellected ! if ts.uniqueId() in seen: continue seen.add(ts.uniqueId()) config = None if configs is not None: config = configs[i] if config is None: config = dict(color=getColor(i)) title = ts.label for j, item in enumerate(ts.for_plotting()): lconfig = config.copy() if len(item) == 2: x, y = item else: x, y, special_config = item lconfig.update(special_config) x = [xi.toordinal() if isinstance(xi, datetime) else xi for xi in x] x_values.extend(x) curve = make_unselectable_curve(x, y, title="<pre>%s</pre>" % title, **lconfig) self.plot.add_item(curve) if j == 0: labels.append(title) items_with_label.append(curve) x_values = sorted(set(x_values)) self.plot.set_x_values(x_values) self.plot.add_item(self.marker) self.plot.add_item(self.label) unique_labels = set(labels) self._add_legend(unique_labels, items_with_label)