Ejemplo n.º 1
0
def show_indexed_timeseries_plotly(timeseries: TimeSeries,
                                   istart=None,
                                   istop=None,
                                   fig: go.FigureWidget = None,
                                   col=None,
                                   row=None,
                                   zero_start=False,
                                   xlabel='time (s)',
                                   ylabel=None,
                                   title=None,
                                   neurodata_vis_spec=None,
                                   **kwargs):
    if ylabel is None and timeseries.unit:
        ylabel = timeseries.unit

    tt = get_timeseries_tt(timeseries, istart=istart, istop=istop)
    if zero_start:
        tt = tt - tt[0]
    data, unit = get_timeseries_in_units(timeseries,
                                         istart=istart,
                                         istop=istop)

    trace_kwargs = dict()
    if col is not None or row is not None:
        trace_kwargs.update(row=row, col=col)
    fig.add_trace(x=tt, y=data, **trace_kwargs, **kwargs)
    layout_kwargs = dict(xaxis_title=xlabel)
    if ylabel is not None:
        layout_kwargs.update(yaxis_title=ylabel)
    if title is not None:
        layout_kwargs.update(title=title)

    fig.update_layout(**layout_kwargs)
Ejemplo n.º 2
0
def show_indexed_timeseries_plotly(
    timeseries: TimeSeries,
    istart: int = 0,
    istop: int = None,
    time_window: list = None,
    trace_range: list = None,
    offsets=None,
    fig: go.FigureWidget = None,
    col=None,
    row=None,
    zero_start=False,
    scatter_kwargs: dict = None,
    figure_kwargs: dict = None,
):
    if istart != 0 or istop is not None:
        if time_window is not None:
            raise ValueError(
                "input either time window or istart/stop but not both")
        if not (0 <= istart < timeseries.data.shape[0] and
                (istop is None or 0 < istop <= timeseries.data.shape[0])):
            raise ValueError("enter correct istart/stop values")
        t_istart = istart
        t_istop = istop
    elif time_window is not None:
        t_istart = timeseries_time_to_ind(timeseries, time_window[0])
        t_istop = timeseries_time_to_ind(timeseries, time_window[1])
    else:
        t_istart = istart
        t_istop = istop
    tt = get_timeseries_tt(timeseries, istart=t_istart, istop=t_istop)
    data, unit = get_timeseries_in_units(timeseries,
                                         istart=t_istart,
                                         istop=t_istop)
    if len(data.shape) == 1:
        data = data[:, np.newaxis]
    if trace_range is not None:
        if not (0 <= trace_range[0] < data.shape[1]
                and 0 < trace_range[1] <= data.shape[1]):
            raise ValueError("enter correct trace range")
        trace_istart = trace_range[0]
        trace_istop = trace_range[1]
    else:
        trace_istart = 0
        trace_istop = data.shape[1]
    if offsets is None:
        offsets = np.zeros(trace_istop - trace_istart)
    if zero_start:
        tt = tt - tt[0]
    scatter_kwargs = dict() if scatter_kwargs is None else scatter_kwargs
    if fig is None:
        fig = go.FigureWidget(make_subplots(rows=1, cols=1))
    row = 1 if row is None else row
    col = 1 if col is None else col
    for i, trace_id in enumerate(range(trace_istart, trace_istop)):
        fig.add_trace(
            go.Scattergl(x=tt,
                         y=data[:, trace_id] + offsets[i],
                         mode="lines",
                         **scatter_kwargs),
            row=row,
            col=col,
        )
    input_figure_kwargs = dict(
        xaxis=dict(title_text="time (s)", range=[tt[0], tt[-1]]),
        yaxis=dict(title_text=unit if unit is not None else None),
        title=timeseries.name,
    )
    if figure_kwargs is None:
        figure_kwargs = dict()
    input_figure_kwargs.update(figure_kwargs)
    fig.update_xaxes(input_figure_kwargs.pop("xaxis"), row=row, col=col)
    fig.update_yaxes(input_figure_kwargs.pop("yaxis"), row=row, col=col)
    fig.update_layout(**input_figure_kwargs)
    return fig