Last active
March 19, 2022 04:26
-
-
Save zaireali649/7715e9819d99d6b4b5d2505dce2b5e6c to your computer and use it in GitHub Desktop.
Randomly generates data and uses Plotly to create a visualization HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import random | |
import plotly.graph_objects as go | |
from plotly.subplots import make_subplots | |
#%% | |
def generate_data(sec = 10, Hz = 32000): | |
time = np.arange(0, sec, 1/Hz) | |
amplitude = (np.random.random(time.shape) - 0.5) * random.randint(10, 25) | |
return time, amplitude | |
#%% | |
colors = [ | |
'#1f77b4', # muted blue | |
'#ff7f0e', # safety orange | |
'#2ca02c', # cooked asparagus green | |
'#d62728', # brick red | |
'#9467bd', # muted purple | |
'#8c564b', # chestnut brown | |
'#e377c2', # raspberry yogurt pink | |
'#7f7f7f', # middle gray | |
'#bcbd22', # curry yellow-green | |
'#17becf' # blue-teal | |
] | |
channels = 3 | |
fig = make_subplots(rows=channels, cols=1) | |
for i in range(channels): | |
ts, amp = generate_data() | |
fig.append_trace(go.Scatter(x=ts, y=amp, | |
line=dict(color=colors[i % 10]), | |
mode='lines', | |
name='Random Data ' + str(i)), row=i+1, col=1) | |
fig.update_layout( | |
title="Random Data Plots", | |
font=dict( | |
family="Courier New, monospace", | |
size=18, | |
color="#7f7f7f" | |
) | |
) | |
fig.write_html("index.html") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment