def array(epochs, xlabel=True, ylabel=True, w=4, h=3, dpi=50): """ plots uts data to a rectangular grid. I data has only 1 dimension, the x-axis defines epochs. **Arguments:** h : scalar plot height in inches w : scalar plot width in inches """ epochs = _base.unpack_epochs_arg(epochs, 2) n_plots = len(epochs) # n = round(np.sqrt(n_plots)) figsize = (n_plots * w, h) fig = plt.figure(figsize=figsize, dpi=dpi) plt.subplots_adjust(.1, .1, .95, .95, .1, .4) for i, layers in enumerate(epochs): ax = fig.add_subplot(1, n_plots, i + 1) _ylabel = ylabel if i == 1 else None _xlabel = xlabel if i == n_plots - 1 else None _ax_im_array(ax, layers, xlabel=_xlabel, ylabel=ylabel) fig.tight_layout() fig.show() return fig
def __init__(self, epochs, sensors=None, ylim=None, w=4, h=2, dpi=90, ncol=3, title=None, axtitle='{name}', xlabel=True, ylabel=True, color=None): """ Parameters ---------- sensors: None or list of sensor IDs sensors to plot (``None`` = all) w, h : scalar width and height of the individual aces in inches color: (mpl color) default (``None``): use segment color if available, otherwise black; ``True``: alternate colors (mpl default) title: bool or string Title for the axes. If ``True``, the segment's name is used. ylim: scalar or (min, max) tuple specifying the y-axis limits (the default ``None`` leaves mpl's default limits unaffected) """ epochs = _base.unpack_epochs_arg(epochs, 2) n_plots = len(epochs) nrow = math.ceil(n_plots / ncol) ncol = min(n_plots, ncol) figsize = (w * ncol, h * nrow) win_title = title if isinstance(title, str) else 'plot.butterfly' super(butterfly, self).__init__(title=win_title, figsize=figsize, dpi=dpi) fig = self.figure for i, layers in enumerate(epochs): ax = fig.add_subplot(nrow, ncol, i + 1) if i == n_plots - 1: _xlabel = xlabel else: _xlabel = None _ax_butterfly(ax, layers, sensors=sensors, ylim=ylim, title=axtitle, xlabel=_xlabel, ylabel=ylabel, color=color) if title: fig.suptitle(title) fig.tight_layout() self._show()
def __init__(self, epochs, sensors=True, proj='default', size=5, dpi=100, title="plot.topomap", res=100, interpolation='nearest'): """ Plots individual topogeraphies. Parameters ---------- sensors : bool | 'id' | 'name' """ epochs = self.epochs = _base.unpack_epochs_arg(epochs, 1) # create figure n_plots = len(epochs) x_size = size * n_plots y_size = size figsize = (x_size, y_size) super(topomap, self).__init__(title=title, figsize=figsize, dpi=dpi) # plot epochs (x/y are in figure coordinates) frame = .05 topo_kwargs = dict(res=res, interpolation=interpolation, proj=proj, sensors=sensors, ) self.axes = [] for i, layers in enumerate(epochs): # axes coordinates left = (i + frame) / n_plots bottom = frame width = (1 - 2 * frame) / n_plots height = 1 - 3 * frame ax_rect = [left, bottom, width, height] ax = self.figure.add_axes(ax_rect) ax.ID = i self.axes.append(ax) _ax_topomap(ax, layers, title=True, **topo_kwargs) self._show()
def __init__(self, epochs, size=2.5, bflywidth=2, dpi=90, res=50, interpolation='nearest', title=True, xlabel=True, ylabel=True, color=None, sensors=None, ylim=None): """ size : float in inches: height of the butterfly axes and side length of the topomap axes bflywidth : float multiplier for the width of butterfly plots based on their height """ epochs = self.epochs = _base.unpack_epochs_arg(epochs) # create figure n_plots = len(epochs) x_size = size * (1 + bflywidth) y_size = size * n_plots # old # figsize = (x_size, y_size) # fig = self.create_figure(figsize=figsize, facecolor='w', dpi=dpi) # new parent = wx.GetApp().shell title = "plot.topo.butterfly" mpl_canvas.CanvasFrame.__init__(self, parent, title, dpi=dpi) fig = self.figure # plot epochs (x/y are in figure coordinates) x_axsep = 1 - (size / x_size) y_axsep = 1 / n_plots frame = .05 frame_lbl = frame * 2 self.topo_kwargs = {'res': res, 'interpolation': interpolation} t = 0 self.topo_axes = [] self.t_markers = [] self.topos = [] for i, layers in enumerate(epochs): y_bottom = 1 - y_axsep * (1 + i) ax1_rect = [frame, y_bottom + frame_lbl, x_axsep - 2 * frame, y_axsep - frame_lbl - frame] ax2_rect = [x_axsep + frame, y_bottom + frame, 1 - x_axsep - 2 * frame, y_axsep - 2 * frame] ax1 = fig.add_axes(ax1_rect) ax1.ID = i t_marker = ax1.axvline(t, color='k') ax2 = fig.add_axes(ax2_rect, frameon=False) ax2.set_axis_off() if len(self.topo_axes) == 0: ax2.set_title('t = %.3f' % t) self._t_title = ax2.title self.topo_axes.append(ax2) self.t_markers.append(t_marker) self.topos.append((t_marker, ax2, layers)) uts._ax_butterfly(ax1, layers, sensors=sensors, ylim=ylim, title=title, xlabel=xlabel, ylabel=ylabel, color=color) # setup callback self.canvas.mpl_connect('button_press_event', self._on_click) self._realtime_topo = True self.canvas.mpl_connect('motion_notify_event', self._on_mouse_motion) self.canvas.store_canvas() self.set_topo_t(0, draw=False) self.Show()
def __init__(self, epochs, title=None, height=3, width=2.5, ntopo=3, dpi=90, ylim=None, t=[], **kwargs): """ Interface for exploring channel by sample plots by extracting topo-plots kwargs ------ title ntopo=None number of topoplots per segment (None -> 6 / nplots) """ # convenience for single segment epochs = _base.unpack_epochs_arg(epochs) # figure properties n_epochs = len(epochs) n_topo_total = ntopo * n_epochs fig_width, fig_height = n_epochs * width, height # fig coordinates x_frame_l = .1 / n_epochs x_frame_r = .025 / n_epochs x_per_ax = (1 - x_frame_l - x_frame_r) / n_epochs # create figure parent = wx.GetApp().shell if isinstance(title, basestring): frame_title = title else: frame_title = "plot.topo.array" # figsize=(fig_width, fig_height) mpl_canvas.CanvasFrame.__init__(self, parent, frame_title, dpi=dpi) fig = self.figure fig.subplots_adjust(left = x_frame_l, bottom = .05, right = 1 - x_frame_r, top = .9, wspace = .1, hspace = .3) if title: fig.suptitle(title) self.title = title # im_array plots self.main_axes=[] ax_height = .4 + .075 * (not title) ax_bottom = .45# + .05*(not title) ax_width = .9 * x_per_ax for i,layers in enumerate(epochs): ax_left = x_frame_l + i * x_per_ax ax = fig.add_axes((ax_left, ax_bottom, ax_width, ax_height), picker=True) # rect = [left, bottom, width, height] self.main_axes.append(ax) ax.ID = i ax.type = 'main' _base._ax_im_array(ax, layers) if i > 0: ax.yaxis.set_visible(False) # topo plots self.windows=[] for i, layers in enumerate(epochs): for j in range(ntopo): ID = i * ntopo + j ax = fig.add_subplot(3, n_topo_total, 2 * n_topo_total + 1 + ID, picker=True, xticks=[], yticks=[]) ax.ID = ID ax.type = 'window' pointer_xy = (.1 + (.85 / n_topo_total) * (.5 + ID), .3) self.windows.append(_Window_Topo(ax, pointer_xy, layers)) # save important properties self.epochs = epochs # if t argument is provided, set topo-pol time points if t: if np.isscalar(t): t = [t] self.setwins(*t) # setup callback self._selected_window = None self.canvas.mpl_connect('pick_event', self._pick_handler) self.canvas.mpl_connect('motion_notify_event', self._motion_handler) self.canvas.store_canvas() self.Show()
def __init__(self, epochs, size=2, bflywidth=3, dpi=90, proj='default', res=100, interpolation='nearest', title=True, xlabel=True, ylabel=True, color=True, sensors=True, ROI=None, ylim=None): """ **Plot atributes:** ROI : list of indices plot a subset of sensors sensors : bool determines whether all sensors are marked in the topo-maps **Figure Layout:** size : scalar in inches: height of the butterfly axes as well as side length of the topomap axes bflywidth : scalar multiplier for the width of butterfly plots based on their height res : int resolution of the topomap plots (res x res pixels) interpolation : 'nearest' | ... matplotlib imshow kwargs """ frame_title = "plot.topo.butterfly: %r" if isinstance(title, basestring): frame_title = frame_title % title else: frame_title = frame_title % getattr(epochs, 'name', '') epochs = self.epochs = _base.unpack_epochs_arg(epochs, 2) n_plots = len(epochs) # create figure x_size = size * (1 + bflywidth) y_size = size * n_plots figsize = (x_size, y_size) super(butterfly, self).__init__(title=frame_title, figsize=figsize, dpi=dpi) # axes sizes frame = .05 # in inches; .4 xframe = frame / x_size x_left_ylabel = 0.5 / x_size if ylabel else 0 x_left_title = 0.5 / x_size x_text = x_left_title / 3 ax1_left = xframe + x_left_title + x_left_ylabel ax1_width = bflywidth / (bflywidth + 1) - ax1_left - xframe / 2 ax2_left = bflywidth / (bflywidth + 1) + xframe / 2 ax2_width = 1 / (bflywidth + 1) - 1.5 * xframe yframe = frame / y_size y_bottomframe = 0.5 / y_size # y_bottom = yframe y_sep = (1 - y_bottomframe) / n_plots height = y_sep - yframe self.topo_kwargs = {'proj': proj, 'res': res, 'interpolation': interpolation, 'sensors': sensors, 'ROI': ROI, 'ROIcolor': color, 'title': False} t = 0 self.topo_axes = [] self.bfly_axes = [] self.topos = [] self.t_markers = [] # plot epochs (x/y are in figure coordinates) for i, layers in enumerate(epochs): bottom = 1 - y_sep * (1 + i) ax1_rect = [ax1_left, bottom, ax1_width, height] ax2_rect = [ax2_left, bottom, ax2_width, height] ax1 = self.figure.add_axes(ax1_rect) ax1.ID = i ax2 = self.figure.add_axes(ax2_rect, frameon=False) ax2.set_axis_off() # t - label if len(self.topo_axes) == n_plots - 1: # ax2.set_title('t = %.3f' % t) # self._t_title = ax2.title self._t_title = ax2.text(.0, 0, 't = %.3f' % t, ha='center') self.bfly_axes.append(ax1) self.topo_axes.append(ax2) self.topos.append((ax2, layers)) show_x_axis = (i == n_plots - 1) utsnd._ax_butterfly(ax1, layers, sensors=ROI, ylim=ylim, title=False, xlabel=show_x_axis, ylabel=ylabel, color=color) if not show_x_axis: # ax1.xaxis.set_visible(False) ax1.xaxis.set_ticklabels([]) # find and print epoch title title = True for l in layers: if title is True: title = getattr(l, 'name', True) if isinstance(title, str): y_text = bottom + y_sep / 2 ax1.text(x_text, y_text, title, transform=self.figure.transFigure, ha='center', va='center', rotation='vertical') # setup callback self.canvas.mpl_connect('button_press_event', self._on_click) self._realtime_topo = True self._frame.store_canvas() self._draw_topo(0, draw=False) self._show()
def __init__(self, epochs, title=None, height=3, width=2.5, ntopo=3, dpi=100, ylim=None, t=[]): """ Channel by sample array-plots with topomaps corresponding to individual time points. kwargs ------ title : str | None title ntopo | int number of topomaps per array-plot """ frame_title = "plot.topo.array: %r" if isinstance(title, basestring): frame_title = frame_title % title else: frame_title = frame_title % getattr(epochs, 'name', '') # convenience for single segment epochs = _base.unpack_epochs_arg(epochs, 2) # figure properties n_epochs = len(epochs) n_topo_total = ntopo * n_epochs left_rim = width / 4 fig_width, fig_height = n_epochs * width + left_rim, height figsize = (fig_width, fig_height) # fig coordinates x_frame_l = .6 / width / n_epochs x_frame_r = .025 / n_epochs x_sep = .01 / n_epochs x_per_ax = (1 - x_frame_l - x_frame_r) / n_epochs # create figure super(array, self).__init__(title=frame_title, dpi=dpi, figsize=figsize) fig = self.figure fig.subplots_adjust(left=x_frame_l, bottom=.05, right=1 - x_frame_r, top=.9, wspace=.1, hspace=.3) if title: fig.suptitle(title) self.title = title # im_array plots self.main_axes = [] ax_height = .4 + .07 * (not title) ax_bottom = .45 # + .05*(not title) for i, layers in enumerate(epochs): ax_left = x_frame_l + i * (x_per_ax + x_sep) ax_right = 1 - x_frame_r - (n_epochs - i - 1) * (x_per_ax + x_sep) ax_width = ax_right - ax_left ax = fig.add_axes((ax_left, ax_bottom, ax_width, ax_height), picker=True) self.main_axes.append(ax) ax.ID = i ax.type = 'main' utsnd._ax_im_array(ax, layers) if i > 0: ax.yaxis.set_visible(False) # topo plots self.windows = [] for i, layers in enumerate(epochs): for j in range(ntopo): ID = i * ntopo + j ax = fig.add_subplot(3, n_topo_total, 2 * n_topo_total + 1 + ID, picker=True, xticks=[], yticks=[]) ax.ID = ID ax.type = 'window' self.windows.append(_Window_Topo(ax, layers)) # save important properties self.epochs = epochs self._ntopo = ntopo # if t argument is provided, set topo-pol time points if t: if np.isscalar(t): t = [t] self.setwins(*t) # setup callback self._selected_window = None self.canvas.mpl_connect('pick_event', self._pick_handler) self.canvas.mpl_connect('motion_notify_event', self._motion_handler) self._frame.store_canvas() self._show()