I have a 2D Numpy array with shape 7x1000.
What Iβd like to do is to plot this array like below:
How can I create this plot using Plotly?
I have a 2D Numpy array with shape 7x1000.
What Iβd like to do is to plot this array like below:
How can I create this plot using Plotly?
@zeyd
What your data represent? To plot a line you should pass to go.Scatter the list of x-coordinates and the list of y-coordinates of the points on that line. Without more information is difficult to get an advice.
the x-coordinate is time in milisecond so in this case I have 1000 points on x-axis equals to 1 second.
Y is correlation in [-1,1] range.
So in this case I have 7 different values of Y for each values of x.
I hope itβs clear now?
You can plot your data similarly to this example:
import plotly.graph_objects as go
import numpy as np
#define synthetic data, somehow similar with yours
x = np.arange(1000)
y = np.sin(x)
data = np.zeros((7, 1000))
a= 0.95 #in your case set the value of a by trial and error or calculating the min/max of each row
for k in range(7):
data[k, :] = 0.5*np.sin(0.3*x)+ a*k # a*k is the vertical translation to avoid line overlapping
#plot data
fig= go.Figure(go.Scatter(x=x, y = data[0,:], name=f"corr{1}", mode ="lines"))
for k in range(1, 7):
fig.add_scatter(x=x, y=data[k, :], mode="lines", name =f"corr{k+1}")
fig.update_layout(width=950, title="Your title", title_x=0.5,
xaxis_title="seconds", yaxis_title="correlation (r)")
fig.show()
You can also give a list of 7 colors , mycolors= ["#f210a5", ......]
and set the line_color = mycolors[k]
for the line plot representing data[k, :]
.