python - How to plot a point-to-point alignment between two sequences of datapoints? -


i'm working on time series dynamic time warping. need plot alignment between datapoints of 2 sequences:

t=[t1,t2,t3,...,tx] s=[s1,s2,s3,...,sy] 

the length of both sequences may vary. have points match, say:

[(1,1),(1,2), (2,2), (3,3), (4,3), (4,4)] 

this read as:

t[1] matches s[1]    t[1] matches s[2]    t[2] matches s[2]    ...    t[4] matches s[4]    

what want achieve this:

enter image description here

or better, (i.e. nothing 2 sequences , alignment): enter image description here

i'm aware of existence of dtw pacakge though doesn't seem include method plot alignment. i'm new plotting using python i'm still in dark when comes matplotlib , numpy, or @ least i'm not sure best approach go using them.

summarizing, need know how plot both sequences, 1 on top of other (subplots might help, believe?) , draw line between each datapoint using python.

you should able plot s , t plt.plot. doing lines between them little trickier. i'm assuming x-axis corresponds xth element of both s , t. in case, if ith element of s , jth element of t paired, plot line between them plt.plot((i, j), (s[i], t[j]), color = 'black')

import matplotlib.pyplot plt #plot signals plt.plot(y1, label = 'signal 1') plt.plot(y2, label = 'signal 2') #plot alignment i, j in matches:     plt.plot((i, j), (y1[i], y2[j]), color = 'black') plt.show() 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -