def plot_spectral_estimate(f, sdf, sdf_ests, limits=None, elabels=()): """ Plot an estimate of a spectral transform against the ground truth. Utility file used in building the documentation """ fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax_limits = (sdf.min() - 2*np.abs(sdf.min()), sdf.max() + 1.25*np.abs(sdf.max())) ax.plot(f, sdf, 'c', label='True S(f)') if not elabels: elabels = ('',) * len(sdf_ests) colors = 'bgkmy' for e, l, c in zip(sdf_ests, elabels, colors): ax.plot(f, e, color=c, linewidth=2, label=l) if limits is not None: ax.fill_between(f, limits[0], y2=limits[1], color=(1, 0, 0, .3), alpha=0.5) ax.set_ylim(ax_limits) ax.legend() return fig
def plot_spectral_estimate(f, sdf, sdf_ests, limits=None, elabels=()): """ Plot an estimate of a spectral transform against the ground truth. Utility file used in building the documentation """ fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax_limits = (sdf.min() - 2 * np.abs(sdf.min()), sdf.max() + 1.25 * np.abs(sdf.max())) ax.plot(f, sdf, 'c', label='True S(f)') if not elabels: elabels = ('', ) * len(sdf_ests) colors = 'bgkmy' for e, l, c in zip(sdf_ests, elabels, colors): ax.plot(f, e, color=c, linewidth=2, label=l) if limits is not None: ax.fill_between(f, limits[0], y2=limits[1], color=(1, 0, 0, .3), alpha=0.5) ax.set_ylim(ax_limits) ax.legend() return fig
def plot_tseries(time_series, fig=None, axis=0, xticks=None, xunits=None, yticks=None, yunits=None, xlabel=None, ylabel=None, yerror=None, error_alpha=0.1, time_unit=None, **kwargs): """plot a timeseries object Arguments --------- time_series: a nitime time-series object fig: a figure handle, opens a new figure if None subplot: an axis number (if there are several in the figure to be opened), defaults to 0. xticks: optional, list, specificies what values to put xticks on. Defaults to the matlplotlib-generated. yticks: optional, list, specificies what values to put xticks on. Defaults to the matlplotlib-generated. xlabel: optional, list, specificies what labels to put on xticks ylabel: optional, list, specificies what labels to put on yticks yerror: optional, UniformTimeSeries with the same sampling_rate and number of samples and channels as time_series, the error will be displayed as a shading above and below the plotted time-series """ if fig is None: fig = plt.figure() if not fig.get_axes(): ax = fig.add_subplot(1, 1, 1) else: ax = fig.get_axes()[axis] #Make sure that time displays on the x axis with the units you want: #If you want to change the time-unit on the visualization from that used to #represent the time-series: if time_unit is not None: tu = time_unit conv_fac = ts.time_unit_conversion[time_unit] #Otherwise, get the information from your input: else: tu = time_series.time_unit conv_fac = time_series.time._conversion_factor this_time = time_series.time / float(conv_fac) ax.plot(this_time, time_series.data.T, **kwargs) if xlabel is None: ax.set_xlabel('Time (%s)' % tu) else: ax.set_xlabel(xlabel) if ylabel is not None: ax.set_ylabel(ylabel) if yerror is not None: if len(yerror.data.shape) == 1: this_e = yerror.data[np.newaxis, :] else: this_e = yerror.data delta = this_e e_u = time_series.data + delta e_d = time_series.data - delta for i in range(e_u.shape[0]): ax.fill_between(this_time, e_d[i], e_u[i], alpha=error_alpha) return fig