Exemple #1
0
def draw_map_plotly(mums, html=None):
    data = []
    for align in mums['+']:
        x = align[0]
        y = align[1]
        length = align[2]
        data.append(go.Scattergl(x=[x,x+length], y=[y,y+length], marker=dict(color='red')))
    for align in mums['-']:
        x = align[0]
        y = align[1]
        length = align[2]
        data.append(go.Scattergl(x=[x,x+length], y=[y,y-length], marker=dict(color='blue')))

    # output
    layout = go.Layout(
        showlegend=False, barmode='stack',
        xaxis=dict(title='reference', domain=[0, 1], showspikes=True, spikemode='across'),
        yaxis=dict(title='query', domain=[0, 1], showspikes=True, spikemode='across')
    )
    fig = go.Figure(data=data, layout=layout)
    if html:
        offline.plot(fig, filename=html, auto_open=False)
    else:
        offline.iplot(fig)
Exemple #2
0
    def plot_prefixspan(self, l):
        all_trace = []
        for elmt in l:
            trace = go.Scattergl(
            y = elmt[1],
            mode = str(self.mode),
            name = str(elmt[0])
            )
            all_trace.append(trace)

        fig = dict(data=all_trace,layout = {
                'xaxis': {'title': 'representation des symbols'},
                'yaxis': {'title': "y"}
                })
        iplot(fig)
Exemple #3
0
def get_zoom_graph(x, y, sf_trigger):
    fig = {
        'data': [
            go.Scattergl(x=x,
                         y=y,
                         mode='markers',
                         marker=dict(color=config.get('ZOOM_GRAPH',
                                                      'POINTS_COLOR'),
                                     size=config.getint(
                                         'ZOOM_GRAPH', 'POINTS_SIZE')))
        ],
        'layout': []
    }

    return fig
Exemple #4
0
def send_data_timeseries(drop_nb, df_json, tab_ttxd):
    if drop_nb is not None:
        if drop_nb != 0:
            df_data = pd.read_json(df_json)
            data_time = []
            time_x = list(df_data.index)
            for idx in tab_ttxd[:drop_nb]:
                data_time.append(
                    go.Scattergl(
                        x=time_x,
                        y=df_data[idx],
                        name=idx,
                        yaxis="y",
                    ))

            data_time.append(
                go.Scattergl(x=time_x,
                             y=df_data["tnh"],
                             name="TNH",
                             yaxis="y2",
                             hoverinfo=("x", "y")))

            fig_timeseries = go.Figure(data=data_time,
                                       layout=layout_timeseries)

        else:

            fig_timeseries = go.Figure(data=[go.Scatter()],
                                       layout=layout_timeseries)

    else:

        fig_timeseries = go.Figure(data=[go.Scatter()],
                                   layout=layout_timeseries)

    return fig_timeseries, template_download_plotly(fig_timeseries, 0)
    def __create_list_of_scatters(self):
        list_of_plotly_scatters = []

        labeled_points = zip(X_tsne, labels_array)
        for l in labels_array:
            points = [point for (point, label) in labeled_points if label == l]
            current_scatter = go.Scattergl(
                x,
                y=zip(*points),
                name=self.ROOM_LABELS[l - 1],
                mode='markers',
            )
            list_of_plotly_scatters.append(current_scatter)

        return list_of_plotly_scatters
    def calc_graph(self):
        data = self.calculate_hourly_loads()
        traces = []
        analysis_fields = self.remove_unused_fields(data, self.analysis_fields)
        for field in analysis_fields:
            y = data[field].values / 1E3  # to MW
            name = NAMING[field]
            trace = go.Scattergl(x=data.index,
                                 y=y,
                                 name=name,
                                 marker=dict(color=COLOR[field]))
            traces.append(trace)

        data_T = self.calculate_external_temperature()
        for field in ["T_ext_C"]:
            y = data_T[field].values
            name = NAMING[field]
            trace = go.Scattergl(x=data_T.index,
                                 y=y,
                                 name=name,
                                 yaxis='y2',
                                 opacity=0.2)
            traces.append(trace)
        return traces
Exemple #7
0
def get_figure_data(jdata, dotsize, word_obs, annot_sel, is_annot):
    x = np.array(jdata['embed'][0])
    y = np.array(jdata['embed'][1])

    def annot_word(i_word, showarrow=True):
        return dict(x=x[i_word + 2],
                    y=y[i_word + 2],
                    xref='x',
                    yref='y',
                    text=jdata['vocab'][i_word + 2],
                    showarrow=showarrow,
                    ax=20,
                    ay=-20)

    if annot_sel == 'obs':
        annots = [annot_word(word_obs)]
    elif annot_sel == 'none':
        annots = []
    else:
        if len(is_annot) > 0:
            annots = [annot_word(i_high) for i_high in is_annot]
        else:
            annots = []
    return {
        'data': [
            go.Scattergl(x=x,
                         y=y,
                         mode='markers',
                         marker=dict(size=dotsize),
                         text=jdata['vocab'])
        ],
        'layout':
        go.Layout(autosize=True,
                  hovermode='closest',
                  yaxis=dict(zeroline=False,
                             range=[y.min() - 5, y.max() + 5],
                             showticklabels=False,
                             mirror=True,
                             showline=True),
                  xaxis=dict(zeroline=False,
                             range=[x.min() - 5, x.max() + 5],
                             showticklabels=False,
                             mirror=True,
                             showline=True),
                  showlegend=False,
                  annotations=annots,
                  margin=go.Margin(l=5, r=5, b=15, t=15, pad=4))
    }
def plot_expression_UMAP(adata, selected_gene):
    traces = []
    traces.append(
        go.Scattergl(
            x=adata.obsm["X_umap"][:, 0],
            y=adata.obsm["X_umap"][:, 1],
            text="Cell ID: " + adata.obs["cell_ID"],
            mode='markers',
            marker={
                'size': 10,
                'line': {
                    'width': 1,
                    'color': 'grey'
                },
                "color": adata.obs_vector(selected_gene),
                "colorscale": "viridis",
                "cmin": 0,
                "cmax": np.max(adata.obs_vector(selected_gene)),
                "colorbar": dict(title=str(selected_gene)),
            },
            unselected={"marker": {
                "opacity": min_opacity,
            }},
            selected={"marker": {
                "opacity": max_opacity,
            }},
        ))
    return {
        'data':
        traces,
        'layout':
        dict(xaxis={"title": "UMAP 1"},
             yaxis={"title": "UMAP 2"},
             margin={
                 'l': 40,
                 'b': 40,
                 't': 10,
                 'r': 10
             },
             legend={
                 'x': 0,
                 'y': 1
             },
             hovermode='closest',
             transition={'duration': 100},
             width=4 * scale,
             height=3 * scale)
    }
Exemple #9
0
def update_graph(ratingcheck, prices):
    dff = transforms.df

    low = prices[0]
    high = prices[1]

    dff = dff.loc[(dff['price'] >= low) & (dff['price'] <= high)]

    if ratingcheck == ['Y']:
        dff = dff.loc[dff['rating'] >= 95]
    else:
        dff

    trace1 = go.Scattergl(x=dff['rating'],
                          y=dff['price'],
                          mode='markers',
                          opacity=0.7,
                          marker={
                              'size': 8,
                              'line': {
                                  'width': 0.5,
                                  'color': 'white'
                              }
                          },
                          name='Price v Rating')
    return html.Div([
        dcc.Graph(id='rating-price',
                  figure={
                      'data': [trace1],
                      'layout':
                      dict(xaxis={
                          'type': 'log',
                          'title': 'Rating'
                      },
                           yaxis={'title': 'Price'},
                           margin={
                               'l': 40,
                               'b': 40,
                               't': 10,
                               'r': 10
                           },
                           legend={
                               'x': 0,
                               'y': 1
                           },
                           hovermode='closest')
                  })
    ])
Exemple #10
0
def generate_row(fig, row, raw_indicators, data) -> tools.make_subplots:
    """
    Generator all the indicator selected by the user for a specific row
    """
    for indicator in raw_indicators.split(','):
        if indicator in data:
            scattergl = go.Scattergl(x=data['date'],
                                     y=data[indicator],
                                     name=indicator)
            fig.append_trace(scattergl, row, 1)
        else:
            logger.info(
                'Indicator "%s" ignored. Reason: This indicator is not found '
                'in your strategy.', indicator)

    return fig
Exemple #11
0
def update_figure(selected_feature1, selected_feature2):

    data = [
        go.Scattergl(
            x=df[selected_feature1],
            y=df[selected_feature2],
            mode = 'markers'
        )
    ]

    return {
        'data': data,
        'layout': go.Layout(
            hovermode='closest'
        )
    }
Exemple #12
0
def create_scatter(x_values, y_values, mode, hovertext):
    """
    """

    tracer = go.Scattergl(
        x=x_values,
        y=y_values,
        mode=mode,
        #line=dict(color='black'),
        line=dict(color='rgba(147,112,219,0.1)'),
        showlegend=False,
        text=hovertext,
        hovertemplate=('%{text}'),
        visible=True)

    return tracer
Exemple #13
0
def make_sub(dfs, df_keys, params):
    traces = []
    for key, df in zip(df_keys, dfs):
        for par in params:
            if par in df.columns:
                this_df = df.dropna(subset=[par])
                if this_df.shape[0] > 0:
                    traces.append(
                        go.Scattergl(x=this_df.index,
                                     y=this_df[par],
                                     name=key + ', ' + par,
                                     mode=graph_mode,
                                     marker=dict(size=5)))
                else:
                    pass
    return traces
def calc_graph(analysis_fields, data_frame):
    graph = []
    duration = range(HOURS_IN_YEAR)
    x = [(a - min(duration)) / (max(duration) - min(duration)) * 100
         for a in duration]  # calculate relative values
    for field in analysis_fields:
        data_frame = data_frame.sort_values(by=field, ascending=False)
        y = data_frame[field].values
        trace = go.Scattergl(x=x,
                             y=y,
                             name=field,
                             fill='tozeroy',
                             opacity=0.8,
                             marker=dict(color=COLOR[field]))
        graph.append(trace)
    return graph
def price_duration_curve(price):
    price = price.sort_values('RRP', ascending=False)
    price = price.reset_index(drop=True)
    price['duration'] = price.index
    price['duration'] = (price['duration'] / price['duration'].max()) * 100
    chart_data = go.Scattergl(x=price['duration'], y=price['RRP'])
    annual_profile_layout = get_default_layout()
    annual_profile_layout['xaxis']['title'] = 'Duration (%)'
    annual_profile_layout['yaxis']['title'] = 'Price ($/MWh)'
    annual_profile_layout['yaxis']['tickvals'] = [
        1, 10, 100, 1000, price['RRP'].max()
    ]
    annual_profile_layout['yaxis']['type'] = 'log'
    chart_data = {'data': [chart_data], 'layout': annual_profile_layout}
    chart_data = json.dumps(chart_data, cls=plotly.utils.PlotlyJSONEncoder)
    return chart_data
Exemple #16
0
def visualize_prediction(file_path: str, prediction_list):
    (fs,
     x) = read('/Users/noresources/Pycharm_projects/InhaleSense/data/raw/' +
               file_path)

    # Create a trace
    predicted = go.Scattergl(x=np.arange(0, x.shape[0]),
                             y=x,
                             marker=dict(color=list(
                                 map(SetColor, np.arange(0, x.shape[0]),
                                     repeat(prediction_list))),
                                         size=1.5,
                                         opacity=0.5),
                             mode="markers")

    return predicted
Exemple #17
0
def cluster_analysis(paths, topn=100):
    model = api.load("glove-wiki-gigaword-200")  #"glove-twitter-50")
    data = []
    vector, labels, names = [], [], []
    cnt = Counter()
    wwords = []

    for path in paths:
        print('Analyzing: ', path)
        x = normalization.normalize_srt(path)
        wwords.append(
            [i for i, _ in word_counter.word_counter(x).most_common(topn)])
        cnt.update(wwords[-1])
        #print(words)

    for path, words in zip(paths, wwords):
        for word in words:
            try:
                if cnt[word] > 1:
                    continue
                vector.append(model.wv[word])
                labels.append(word)
                names.append(path)
            except Exception as e:
                print(e)
                print("Not found %s in vector" % word)

    embedded = TSNE(n_components=2, init='pca').fit_transform(vector)
    x, y = np.hsplit(embedded, 2)
    x = x.reshape(-1)
    y = y.reshape(-1)
    last = 0
    for i in range(len(names)):
        if i + 1 == len(names) or names[i] != names[i + 1]:
            print(last, i)

            trace = go.Scattergl(
                x=x[last:i],
                y=y[last:i],
                mode='markers',
                # marker=dict(color='#FFBAD2', line=dict(width=1)),
                text=labels[last:i],
                name=names[i])
            last = i + 1
            data.append(trace)

    plotly.offline.plot(data, filename='compare_webgl.html')
Exemple #18
0
def plot_chart(path_to_png, path_to_log_list):
    print(path_to_png[0:-4] + ".html")
    output_file(path_to_png[0:-4] + ".html")
    TOOLS = 'pan,box_zoom,wheel_zoom,save,hover,reset,resize'
    p = figure(title="TrainLoss(smoothed) vs NumIters",
               x_axis_label='NumIters')
    fig, ax1 = plt.subplots()

    cf.set_config_file(offline=False, world_readable=True, theme='ggplot')
    for path_to_log in path_to_log_list:
        os.system('%s %s ./ ' % (get_log_parsing_script(), path_to_log))
        data_file = get_data_file(6, path_to_log)
        pddata = pd.read_csv(data_file)
        standard = ['NumIters', 'Seconds', 'LearningRate']
        labels = [label for label in pddata if label not in standard]
        sp = 500 if len(pddata['NumIters']) > 2000 else 5
        skip = 5 if len(pddata['NumIters']) > 2000 else 0
        ylims = [100, -100]
        data = []
        for label, i in zip(labels, range(len(labels))):
            Y = pddata[label].ewm(span=sp, adjust=True).mean()
            plt.plot(pddata["NumIters"], Y, alpha=0.4)
            ylims[0] = min(ylims[0], Y[skip:].min())
            ylims[1] = max(ylims[1], Y[skip:].max())
            data += [go.Scattergl(x=pddata["NumIters"], y=Y, name=label)]
            # p.line(pddata["NumIters"], Y, legend=label,
            #         color=Spectral11[i%11], line_width=2)
        print(int(pddata["NumIters"].iloc[-1]))
        plt.legend()

        ax1.set_ylim(ylims)
        # p.extra_y_ranges = {"LearningRate": Range1d(start=0, end=pddata['LearningRate'].max()*1.1)}
        # p.add_layout(LinearAxis(y_range_name="LearningRate"), 'right')
        # p.line(pddata["NumIters"],
        #        pddata['LearningRate'],
        #        legend='LearningRate',
        #        color='navy', y_range_name="LearningRate")
        # p.add_layout(LinearAxis(y_range_name="LearningRate"), 'left')
    # save(p)
    # ax2 = ax1.twinx()
    # ax2.plot(pddata["NumIters"], pddata['LearningRate'], alpha=0.4)
    plt.title('TrainLoss vs NumIters')
    # ax2.set_ylabel('Learning Rate', color='r')
    plt.xlabel('NumIters')
    plt.savefig(path_to_png)
    url = py.plot(data, filename=path_to_png[0:-4], fileopt='overwrite')
    print(url)
def generate_plotly_scatter(x,
                            y,
                            c,
                            x_label,
                            y_label,
                            text,
                            figsize,
                            marker_size=8,
                            dpi=40,
                            alpha=0.8,
                            cbar_title=None,
                            colormap='Hot',
                            save_to_path=None,
                            show=True,
                            publish_name=None):
    data = [
        go.Scattergl(x=x,
                     y=y,
                     text=text,
                     hoverinfo='text',
                     mode='markers',
                     marker=dict(
                         size=marker_size,
                         color=c,
                         colorscale=colormap,
                         showscale=True,
                         opacity=alpha,
                         colorbar=dict(title=cbar_title),
                     ))
    ]
    layout = go.Layout(xaxis=dict(title=x_label),
                       yaxis=dict(title=y_label),
                       hovermode='closest',
                       width=figsize[0] * dpi,
                       height=figsize[1] * dpi)
    fig = go.Figure(data=data, layout=layout)
    if publish_name:
        py.plotly.plot(fig,
                       filename=publish_name,
                       show_link=True,
                       auto_open=False)
    if save_to_path:
        py.offline.plot(fig,
                        filename=save_to_path,
                        show_link=False,
                        auto_open=False)
    if show: py.offline.iplot(fig, show_link=False)
Exemple #20
0
def display(data, title, xlabel, ylabel):
    app = dash.Dash(__name__)
    app.layout = html.Div(children=[
        html.H1(children=title),
        dcc.Graph(id='graph',
                  figure={
                      'data': [
                          go.Scattergl(x=list(zip(*data))[0],
                                       y=list(zip(*data))[1],
                                       mode='markers')
                      ],
                      'layout':
                      go.Layout(xaxis={'title': xlabel},
                                yaxis={'title': ylabel})
                  })
    ])
    app.run_server(host='0.0.0.0', debug=False)
Exemple #21
0
def _scatter(coords, *args, **kwargs):
    """Run the appropriate scatter function"""
    assert coords.shape[1] in [2, 3], "incorrect dimensions for coords"
    if coords.shape[1] == 2:
        try:
            return go.Scattergl(x=coords[:, 0],
                                y=coords[:, 1],
                                *args,
                                **kwargs)
        except AttributeError:
            return go.Scatter(x=coords[:, 0], y=coords[:, 1], *args, **kwargs)
    else:
        return go.Scatter3d(x=coords[:, 0],
                            y=coords[:, 1],
                            z=coords[:, 2],
                            *args,
                            **kwargs)
Exemple #22
0
def get_embedding_scatterplots(embeddings, sizes, opacity_states, colors, names):
    """ AAA
    """
    data = []
    for embedding, size, opacity, color, name in zip(embeddings, sizes, opacity_states, colors, names):
        temp_data = go.Scattergl(x=embedding['Z1'], y=embedding['Z2'], mode='markers',
                                 marker=dict(color=color, size=size, opacity=opacity), hoverinfo='text',
                                 hovertext=embedding['text'], customdata=embedding.index.tolist(),
                                 name=name)
        data.append(temp_data)

    layout = go.Layout(xaxis=dict(showticklabels=False, ticks=''), yaxis=dict(showticklabels=False, ticks=''),
                       margin=dict(t=30), paper_bgcolor='rgba(0,0,0,0)', clickmode='event+select', showlegend=True,
                       legend=dict(font=dict(color="white")), legend_orientation="h")

    fig = go.Figure(data=data, layout=layout)
    return fig
Exemple #23
0
 def plot_scatter_by_capteur(self, data, capteur):
     all_trace = []
     for cpt in capteur:
         for k, v in data.items():
             if cpt in k:
                 trace = go.Scattergl(
                 x = data[k]["Date"],
                 y = data[k]["Valeur"],
                 mode = str(self.mode),
                 name = str(str(k))
                 )
                 all_trace.append(trace)
     fig = dict(data=all_trace,layout = {
             'xaxis': {'title': 'Le temps'},
             'yaxis': {'title': "La valeur"}
             })
     iplot(fig)
def get_scatter_plot(df_trans, x, y, title='Scatter Plot'):
    trace1 = go.Scattergl(x=df_trans[x],
                          y=df_trans[y],
                          text=df_trans[x].index,
                          mode='markers',
                          marker=dict(size=2))
    trace2 = go.Box(x=df_trans[x],
                    text=df_trans[x].index,
                    name=x,
                    boxpoints='outliers',
                    jitter=0,
                    marker=dict(size=2),
                    yaxis='y2')
    trace3 = go.Box(y=df_trans[y],
                    text=df_trans[y].index,
                    name=y,
                    boxpoints='outliers',
                    jitter=0,
                    marker=dict(size=2),
                    xaxis='x2')
    vs_traces = [trace1, trace2, trace3]
    vs_layout = go.Layout(title=title.format(x, y),
                          hovermode='closest',
                          titlefont=dict(size=14, color='#0e4886'),
                          xaxis=dict(tickfont=dict(size=10),
                                     titlefont=dict(color='#0e4886'),
                                     title=x,
                                     domain=[0, 0.85],
                                     showgrid=False),
                          xaxis2=dict(domain=[0.85, 1],
                                      showticklabels=False,
                                      showgrid=False),
                          yaxis=dict(tickfont=dict(size=10),
                                     title=y,
                                     titlefont=dict(color='#0e4886'),
                                     domain=[0, 0.85],
                                     showgrid=False),
                          yaxis2=dict(domain=[0.85, 1],
                                      showticklabels=False,
                                      showgrid=False),
                          showlegend=False,
                          font=dict(size=10),
                          margin=dict(l=45, r=5, t=30, b=30))

    fig = go.Figure(data=vs_traces, layout=vs_layout)
    return fig
        def generate_row(fig, row, raw_indicators, data) -> tools.make_subplots:
            """
            Generator all the indicator selected by the user for a specific row
            """
            if raw_indicators is None or raw_indicators == "":
                return fig
            for indicator in raw_indicators.split(','):
                if indicator in data:
                    scattergl = go.Scattergl(
                        x=data['date'],
                        y=data[indicator],
                        name=indicator
                    )
                fig.append_trace(scattergl, row, 1)


            return fig
Exemple #26
0
def plot_2d_scatter(df,
                    x,
                    y,
                    xlab='',
                    ylab='',
                    title='',
                    filename='2d-scatter.html',
                    inline=False):
    # Create a trace
    trace = go.Scattergl(x=df[x], y=df[y], mode='markers')

    data = [trace]
    if inline:
        init_notebook_mode()
        iplot(data, filename=filename)
    else:
        plot(data, filename=filename)
Exemple #27
0
def plot_2D_scatter(x,
                    y,
                    text='',
                    title='',
                    xlab='',
                    ylab='',
                    hoverinfo='text',
                    color='black',
                    colorscale='Blues',
                    size=8,
                    showscale=False,
                    symmetric_x=False,
                    symmetric_y=False,
                    pad=0.5,
                    hline=False,
                    vline=False,
                    return_trace=False):
    range_x = [-max(abs(x)) - pad, max(abs(x)) + pad] if symmetric_x else []
    range_y = [-max(abs(y)) - pad, max(abs(y)) + pad] if symmetric_y else []
    trace = go.Scattergl(x=x,
                         y=y,
                         mode='markers',
                         text=text,
                         hoverinfo=hoverinfo,
                         hovermode='closest',
                         marker={
                             'color': color,
                             'colorscale': colorscale,
                             'showscale': showscale,
                             'size': size
                         })
    if return_trace:
        return trace
    else:
        layout = go.Layout(title=title,
                           xaxis={
                               'title': xlab,
                               'range': range_x
                           },
                           yaxis={
                               'title': ylab,
                               'range': range_y
                           },
                           hovermode='closest')
        fig = go.Figure(data=[trace], layout=layout)
        return iplot(fig)
Exemple #28
0
def plotly_clips(bam_path):
    import plotly.offline as py
    import plotly.graph_objs as go
    aln = list(parse_bam(bam_path).items())[0][1]
    aligned_depth = [sum(weight.values()) for weight in aln.weights]
    ins = [sum(i.values()) for i in aln.insertions]
    x_axis = list(range(len(aligned_depth)))
    traces = [
        go.Scattergl(x=x_axis,
                     y=aligned_depth,
                     mode='lines',
                     name='Aligned depth'),
        go.Scattergl(x=x_axis,
                     y=aln.consensus_depth,
                     mode='lines',
                     name='Consensus depth'),
        go.Scattergl(x=x_axis,
                     y=aln.clip_start_depth,
                     mode='lines',
                     name='Soft clip start depth'),
        go.Scattergl(x=x_axis,
                     y=aln.clip_end_depth,
                     mode='lines',
                     name='Soft clip end depth'),
        go.Scattergl(x=x_axis,
                     y=aln.clip_starts,
                     mode='markers',
                     name='Soft clip starts'),
        go.Scattergl(x=x_axis,
                     y=aln.clip_ends,
                     mode='markers',
                     name='Soft clip ends'),
        go.Scattergl(x=x_axis, y=ins, mode='markers', name='Insertions'),
        go.Scattergl(x=x_axis,
                     y=aln.deletions,
                     mode='markers',
                     name='Deletions')
    ]
    layout = go.Layout(xaxis=dict(type='linear', autorange=True),
                       yaxis=dict(type='linear', autorange=True))
    fig = go.Figure(data=traces, layout=layout)
    out_fn = os.path.splitext(os.path.split(bam_path)[1])[0]
    py.plot(fig, filename=out_fn + '.clips.html')
Exemple #29
0
def visualize_groundtruth(file_path: str, relevant):
    (fs,
     x) = read('/Users/noresources/Pycharm_projects/InhaleSense/data/raw/' +
               file_path)

    Exhale = []
    Inhale = []
    Drug = []
    for idx, snippet in relevant.iterrows():
        if snippet[1] == 'Exhale':
            Exhale.append({'begin': snippet[2], 'end': snippet[3]})
        elif snippet[1] == 'Inhale':
            Inhale.append({'begin': snippet[2], 'end': snippet[3]})
        elif snippet[1] == 'Drug':
            Drug.append({'begin': snippet[2], 'end': snippet[3]})

    # print(Exhale, Inhale, Drug)

    # function below sets the color based on amount
    def SetColor_range(x):
        for exh in Exhale:
            if exh['begin'] < x and exh['end'] > x:
                return "red"

        for inh in Inhale:
            if inh['begin'] < x and inh['end'] > x:
                return "blue"

        for dru in Drug:
            if dru['begin'] < x and dru['end'] > x:
                return "green"

        return "black"

    # Create a trace
    ground_truth = go.Scattergl(x=np.arange(0, x.shape[0]),
                                y=x,
                                marker=dict(color=list(
                                    map(SetColor_range,
                                        np.arange(0, x.shape[0]))),
                                            size=1.5,
                                            opacity=0.5),
                                mode="markers")

    return ground_truth
def _make_trace2d(neuron,
                  plane,
                  prefix='',
                  opacity=1.,
                  visible=True,
                  style=None,
                  line_width=2):
    '''Create the trace to be plotted'''
    names = defaultdict(int)
    lines = list()
    for neurite in iter_neurites(neuron):
        names[neurite.type] += 1

        try:
            neurite_color = style[neurite]['color']
        except KeyError:
            neurite_color = TREE_COLOR.get(neurite.root_node.type, 'black')

        name = _neurite_name(neurite, prefix, names)

        for section in iter_sections(neurite):
            segs = [(s[0][COLS.XYZ], s[1][COLS.XYZ])
                    for s in iter_segments(section)]

            try:
                colors = style[section]['color']
            except KeyError:
                colors = neurite_color

            coords = dict()
            for i, coord in enumerate('xyz'):
                coords[coord] = list(
                    chain.from_iterable(
                        (p1[i], p2[i], None) for p1, p2 in segs))

            coords = dict(x=coords[plane[0]], y=coords[plane[1]])
            lines.append(
                go.Scattergl(name=name,
                             visible=visible,
                             opacity=opacity,
                             showlegend=False,
                             line=dict(color=colors, width=line_width),
                             mode='lines',
                             **coords))
    return lines