Skip to content

Instantly share code, notes, and snippets.

@bendichter
Last active December 3, 2020 19:50
Show Gist options
  • Save bendichter/198aa06da55b4ef1955fbf7f0e932a7f to your computer and use it in GitHub Desktop.
Save bendichter/198aa06da55b4ef1955fbf7f0e932a7f to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
import plotly.graph_objs as go
import numpy as np
import dash_core_components as dcc
import dash_html_components as html
import dash
def display_eletrode_turns(all_turn_data):
"""
all_turn_data: list of data for each electrode, [(times,turns), ...]
"""
data = [
{
"x": np.r_[start, turn_times],
"y": np.r_[0, np.cumsum(turns)],
"line": {"shape": 'hv'},
"mode": 'lines+markers',
"name": 'value',
"type": 'scatter',
"name": 'elec{}'.format(i)
} for i, (turn_times, turns) in enumerate(all_turn_data)]
layout = go.Layout(
showlegend=False,
yaxis = dict(
title='depth (mm)'
)
)
fig = go.Figure(data=data, layout=layout)
return fig
# generate fake data
start = datetime(1900, 1, 1)
nchans = 10
max_turn = 300
max_time_interval = 30 # days
n_turns = 5
all_data = []
for chan in range(nchans):
turn_times = start + np.cumsum([timedelta(days=np.random.randint(max_time_interval)) for _ in range(n_turns)])
turns = np.random.randint(max_turn, size=turn_times.shape)
all_data.append(
(turn_times,
turns)
)
display_eletrode_turns(all_data)
@bendichter
Copy link
Author

bendichter commented Dec 3, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment