def test(): """Test""" # -- Create QApplication import guidata _app = guidata.qapplication() # -- from numpy import linspace, sin x = linspace(-10, 10, 200) dy = x / 100.0 y = sin(sin(sin(x))) x2 = linspace(-10, 10, 20) y2 = sin(sin(sin(x2))) curve2 = make.curve(x2, y2, color="g", curvestyle="Sticks") curve2.setTitle("toto") plot( make.curve(x, y, color="b"), curve2, make.curve(x, sin(2 * y), color="r"), make.merror(x, y / 2, dy), make.label("Relative position <b>outside</b>", (x[0], y[0]), (-10, -10), "BR"), make.label("Relative position <i>inside</i>", (x[0], y[0]), (10, 10), "TL"), make.label("Absolute position", "R", (0, 0), "R"), make.legend("TR"), make.marker( position=(5.0, 0.8), label_cb=lambda x, y: "A = %.2f" % x, markerstyle="|", movable=False, ), )
def test(): """Test""" # -- Create QApplication import guidata _app = guidata.qapplication() # -- from numpy import linspace, sin x = linspace(-10, 10, 200) dy = x / 100.0 y = sin(sin(sin(x))) x2 = linspace(-10, 10, 20) y2 = sin(sin(sin(x2))) curve2 = make.curve(x2, y2, color="g", curvestyle="Sticks") curve2.setTitle("toto") plot( make.curve(x, y, color="b"), curve2, make.curve(x, sin(2 * y), color="r"), make.merror(x, y / 2, dy), make.label("Relative position <b>outside</b>", (x[0], y[0]), (-10, -10), "BR"), make.label("Relative position <i>inside</i>", (x[0], y[0]), (10, 10), "TL"), make.label("Absolute position", "R", (0, 0), "R"), make.legend("TR"), make.marker(position=(5.0, 0.8), label_cb=lambda x, y: "A = %.2f" % x, markerstyle="|", movable=False), )
def add_epochs(plot, epochs, units=None): """ Add Epoch markers to a guiqwt plot. :param plot: The plot object. :type plot: :class:`guiqwt.baseplot.BasePlot` :param sequence epochs: The epochs (neo :class:`neo.Epoch` objects). :param units: The x-scale of the plot. If this is ``None``, the time unit of the events will be use. """ for e in epochs: if units: start = e.time.rescale(units) end = (e.time + e.duration).rescale(units) else: start = e.time end = e.time + e.duration time = (start + end) / 2.0 o = make.range(start, end) o.setTitle(e.label) o.set_readonly(True) o.set_movable(False) o.set_resizable(False) o.set_selectable(False) o.set_rotatable(False) plot.add_item(o) nameObject = _MarkerName(e.label) plot.add_item(make.marker( (time, 0), nameObject.get_name, movable=False, markerstyle='|', color='k', linestyle='NoPen', linewidth=1))
def create_rt_ms2_marker(): marker = make.marker(position=(0, 0), markerstyle="|", label_cb=lambda x, y: "<div style='color:red'>rt_ms2</div>", constraint_cb=lambda x, y: (x, y), movable=False, readonly=False, color="#ff7777", linewidth=1) # else the get_unique_item methods in modified_guiqwt fail: class DummyMarkerAsOnlyOneTrueMarkerIsAllowed(Marker): pass marker.__class__ = DummyMarkerAsOnlyOneTrueMarkerIsAllowed return marker
def _split_plot_hor(channels, spikes, ref_units, time_unit, progress, plot): """ Fill a plot with spikeshorizontally split by channel. Returns legend. """ legend_items = [] offset = 0 * time_unit for c in channels: for u in spikes.keys(): first_wave = True color = helper.get_object_color(u) for s in spikes[u]: if s.waveform is None or s.sampling_rate is None: raise SpykeException( 'Cannot create waveform plot: ' 'At least one spike has no ' 'waveform or sampling rate!') x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) curve = make.curve( x + offset, s.waveform[:, c].rescale(ref_units), u.name, color=color) if c == channels[0] and first_wave: legend_curve = make.curve( sp.array([0]), sp.array([0]), u.name, color=color, linewidth=2) legend_items.append(legend_curve) plot.add_item(legend_curve) first_wave = False plot.add_item(curve) progress.step() offset += x[-1] if c != channels[-1]: plot.add_item( make.marker((offset, 0), lambda x, y: '', movable=False, markerstyle='|', color='k', linestyle='-', linewidth=1)) l = make.legend(restrict_items=legend_items) plot.add_item(l) plot.set_axis_title(BasePlot.Y_LEFT, 'Voltage') plot.set_axis_unit( BasePlot.Y_LEFT, ref_units.dimensionality.string) return l
def add_events(plot, events, units=None): """ Add Event markers to a guiqwt plot. :param plot: The plot object. :type plot: :class:`guiqwt.baseplot.BasePlot` :param sequence events: The events (neo :class:`neo.Event` objects). :param Quantity units: The x-scale of the plot. If this is ``None``, the time unit of the events will be use. """ for m in events: nameObject = _MarkerName(m.label) if units: time = m.time.rescale(units) else: time = m.time plot.add_item( make.marker( (time, 0), nameObject.get_name, movable=False, markerstyle='|', color='k', linestyle=':', linewidth=1))
def add_events(plot, events, units=None): """ Add Event markers to a guiqwt plot. :param plot: The plot object. :type plot: :class:`guiqwt.baseplot.BasePlot` :param sequence events: The events (neo :class:`neo.Event` objects). :param Quantity units: The x-scale of the plot. If this is ``None``, the time unit of the events will be use. """ for m in events: nameObject = _MarkerName(m.label) if units: time = m.time.rescale(units) else: time = m.time plot.add_item( make.marker((time, 0), nameObject.get_name, movable=False, markerstyle='|', color='k', linestyle=':', linewidth=1))
def add_epochs(plot, epochs, units=None): """ Add Epoch markers to a guiqwt plot. :param plot: The plot object. :type plot: :class:`guiqwt.baseplot.BasePlot` :param sequence epochs: The epochs (neo :class:`neo.Epoch` objects). :param units: The x-scale of the plot. If this is ``None``, the time unit of the events will be use. """ for e in epochs: if units: start = e.time.rescale(units) end = (e.time + e.duration).rescale(units) else: start = e.time end = e.time + e.duration time = (start + end) / 2.0 o = make.range(start, end) o.setTitle(e.label) o.set_readonly(True) o.set_movable(False) o.set_resizable(False) o.set_selectable(False) o.set_rotatable(False) plot.add_item(o) nameObject = _MarkerName(e.label) plot.add_item( make.marker((time, 0), nameObject.get_name, movable=False, markerstyle='|', color='k', linestyle='NoPen', linewidth=1))
def _split_plot_hor(channels, spikes, strong, fade, ref_units, time_unit, progress, plot): """ Fill a plot with spikeshorizontally split by channel. Returns legend. """ offset = 0 * time_unit for c in channels: x_off = 0 * time_unit for u in spikes: color = helper.get_object_color(u) qcol = Qt.QColor(color) alpha = fade if fade > 0.0 else 1.0 alpha_step = 1.0 - fade if fade > 0.0 else -1.0 - fade alpha_step /= len(spikes[u]) if len(spikes[u]) == 1: alpha = 1.0 for s in spikes[u]: if s.waveform is None or s.sampling_rate is None: raise SpykeException('Cannot create waveform plot: ' 'At least one spike has no ' 'waveform or sampling rate!') x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) x_off = max(x_off, x[-1]) curve = make.curve(x + offset, s.waveform[:, c].rescale(ref_units), u.name, color=color) qcol.setAlphaF(alpha) curve.setPen(Qt.QPen(qcol)) alpha += alpha_step plot.add_item(curve) progress.step() for u in strong: color = helper.get_object_color(u) for s in strong[u]: x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) x_off = max(x_off, x[-1]) outline = make.curve(x + offset, s.waveform[:, c].rescale(ref_units), color='#000000', linewidth=4) curve = make.curve(x + offset, s.waveform[:, c].rescale(ref_units), color=color, linewidth=2) plot.add_item(outline) plot.add_item(curve) progress.step() offset += x_off if c != channels[-1]: plot.add_item( make.marker((offset, 0), lambda x, y: '', movable=False, markerstyle='|', color='k', linestyle='-', linewidth=1)) l = _add_legend(plot, spikes, strong) return l
def _split_plot_hor(channels, spikes, strong, fade, ref_units, time_unit, progress, plot): """ Fill a plot with spikeshorizontally split by channel. Returns legend. """ offset = 0 * time_unit for c in channels: x_off = 0 * time_unit for u in spikes: color = helper.get_object_color(u) qcol = Qt.QColor(color) alpha = fade if fade > 0.0 else 1.0 alpha_step = 1.0 - fade if fade > 0.0 else -1.0 - fade alpha_step /= len(spikes[u]) if len(spikes[u]) == 1: alpha = 1.0 for s in spikes[u]: if s.waveform is None or s.sampling_rate is None: raise SpykeException( 'Cannot create waveform plot: ' 'At least one spike has no ' 'waveform or sampling rate!') x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) x_off = max(x_off, x[-1]) curve = make.curve( x + offset, s.waveform[:, c].rescale(ref_units), u.name, color=color) qcol.setAlphaF(alpha) curve.setPen(Qt.QPen(qcol)) alpha += alpha_step plot.add_item(curve) progress.step() for u in strong: color = helper.get_object_color(u) for s in strong[u]: x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) x_off = max(x_off, x[-1]) outline = make.curve( x + offset, s.waveform[:, c].rescale(ref_units), color='#000000', linewidth=4) curve = make.curve( x + offset, s.waveform[:, c].rescale(ref_units), color=color, linewidth=2) plot.add_item(outline) plot.add_item(curve) progress.step() offset += x_off if c != channels[-1]: plot.add_item( make.marker((offset, 0), lambda x, y: '', movable=False, markerstyle='|', color='k', linestyle='-', linewidth=1)) l = _add_legend(plot, spikes, strong) return l
def spikes(spikes, axes_style, anti_alias=False, time_unit=pq.ms, progress=None): """ Create a plot dialog with spike waveforms. :param dict spikes: A dictionary of spike lists. :param int axes_style: Plotting mode. The following values are possible: 1 Show each channel in a seperate plot. 2 Show all channels in the same plot vertically. 3 Show all channels in the same plot horizontally. :param bool anti_alias: Determines whether an antialiased plot is created. :param Quantity time_unit: The (time) unit for the x axis :param progress: Set this parameter to report progress. :type progress: :class:`spykeutils.progress_indicator.ProgressIndicator` """ if not spikes or sum((len(l) for l in spikes.itervalues())) < 1: raise SpykeException('No spikes for spike waveform plot!') if not progress: progress = ProgressIndicator() progress.begin('Creating waveform plot') progress.set_ticks(sum((len(l) for l in spikes.itervalues()))) win_title = 'Spike waveforms' win = PlotDialog(toolbar=True, wintitle=win_title) indices = spikes.keys() ref_spike = spikes[spikes.keys()[0]][0] if ref_spike.waveform is None: raise SpykeException('Cannot create waveform plot: At least one spike ' 'has no waveform or sampling rate!') ref_units = ref_spike.waveform.units channels = range(ref_spike.waveform.shape[1]) plot = None if axes_style == 1: # Separate channel plots for c in channels: pW = BaseCurveWidget(win) plot = pW.plot plot.set_antialiasing(anti_alias) for u in indices: color = helper.get_object_color(u) for s in spikes[u]: if s.waveform is None or s.sampling_rate is None: raise SpykeException('Cannot create waveform plot: ' 'At least one spike has no ' 'waveform or sampling rate!') x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) curve = make.curve(x, s.waveform[:, c].rescale(ref_units), title=u.name, color=color) plot.add_item(curve) progress.step() win.add_plot_widget(pW, c) helper.make_window_legend(win, indices, True) else: # Only one plot needed pW = BaseCurveWidget(win) plot = pW.plot plot.set_antialiasing(anti_alias) legend_items = [] if axes_style == 3: # Horizontal split offset = 0 * time_unit for c in channels: for u in indices: first_wave = True color = helper.get_object_color(u) for s in spikes[u]: if s.waveform is None or s.sampling_rate is None: raise SpykeException('Cannot create waveform plot: ' 'At least one spike has no ' 'waveform or sampling rate!') x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) curve = make.curve(x + offset, s.waveform[:, c].rescale(ref_units), u.name, color=color) if c == channels[0] and first_wave == True: legend_items.append(curve) first_wave = False plot.add_item(curve) progress.step() offset += x[-1] if c != channels[-1]: plot.add_item(make.marker((offset, 0), lambda x,y: '', movable=False, markerstyle='|', color='k', linestyle='-', linewidth=1)) else: # Vertical split channels.reverse() # Find plot y offset maxY = [] minY = [] for i, c in enumerate(channels): maxY.append(max(max(s.waveform[:, c].max() for s in d) for d in spikes.itervalues())) minY.append(min(min(s.waveform[:, c].min() for s in d) for d in spikes.itervalues())) maxOffset = 0 * ref_units for i in range(1, len(channels)): offset = maxY[i - 1] - minY[i] if offset > maxOffset: maxOffset = offset offset = 0 * ref_units for c in channels: for u in indices: first_wave = True color = helper.get_object_color(u) for s in spikes[u]: if s.waveform is None or s.sampling_rate is None: raise SpykeException('Cannot create waveform plot: ' 'At least one spike has no ' 'waveform or sampling rate!') x = (sp.arange(s.waveform.shape[0]) / s.sampling_rate).rescale(time_unit) curve = make.curve(x, s.waveform[:, c].rescale(ref_units) + offset, u.name, color=color) if c == channels[0] and first_wave == True: legend_items.append(curve) first_wave = False plot.add_item(curve) progress.step() offset += maxOffset l = make.legend(restrict_items=legend_items) plot.add_item(l) win.add_plot_widget(pW, 0) win.add_legend_option([l], True) win.add_custom_curve_tools() progress.done() win.show() plot.set_axis_title(BasePlot.X_BOTTOM, 'Time') plot.set_axis_unit(BasePlot.X_BOTTOM, x.dimensionality.string) if axes_style == 1: win.add_x_synchronization_option(True, channels) win.add_y_synchronization_option(True, channels) if len(channels) == 1 or axes_style > 1: plot.set_axis_title(BasePlot.Y_LEFT, 'Voltage') plot.set_axis_unit(BasePlot.Y_LEFT, ref_units.dimensionality.string) return win