Wolfram Research

Function Repository Resource:

CrossRecurrencePlot

Source Notebook

Visualize the overlap of two discrete time series

Contributed by: Daniel de Souza Carvalho

ResourceFunction["CrossRecurrencePlot"][ts1,ts2]

views the cross recurrence plot of the given time series ts1 and ts2.

Details and Options

ResourceFunction["CrossRecurrencePlot"] plots i on a horizontal axis and j on a vertical axis, where is a phase space trajectory: (i)≈(j)
The recurrence plot is based on the function where Θ is a unit step and ε a threshold
A recurrence plot is a matrix visualization where columns and rows correspond to a certain pair of times.
Setting the option "RecurrenceType""Global" replaces the function Θ used in the definition of Ri,j with the identity. The default setting of "RecurrenceType""Standard" preserves Θ.
The option “RecurrenceThreshold” allows the value of ε to be set.
CrossRecurrencePlot also takes all the options of ArrayPlot.

Examples

Basic Examples

View the cross recurrence plot of two random lists:

In[1]:=
ResourceFunction["CrossRecurrencePlot"][RandomInteger[10, 100], RandomInteger[10, 100]]
Out[1]=

View the cross recurrence plot of just one list of random integer values. Note the symmetry across the diagonal:

In[2]:=
ResourceFunction["CrossRecurrencePlot"][#, #] &[
 RandomInteger[10, 100]]
Out[2]=

Visualize the cross recurrence plot of the Sinc function with a recurrence type of "Global":

In[3]:=
ResourceFunction["CrossRecurrencePlot"][#, #, "RecurrenceType" -> "Global"] &[Table[Sinc[x], {x, -7, 7, .1}]]
Out[3]=

View the cross recurrence plot of a range and a random list of integers:

In[4]:=
ResourceFunction["CrossRecurrencePlot"][Range[100], RandomInteger[10, 100], "RecurrenceType" -> "Global", ColorFunction -> "DeepSeaColors"]
Out[4]=

View a cross recurrent plot of equal ranges:

In[5]:=
ResourceFunction["CrossRecurrencePlot"][Range[10], Range[10], Mesh -> True]
Out[5]=

View a cross recurrence plot of two different small lists:

In[6]:=
ResourceFunction[
 "CrossRecurrencePlot"][{7, 10, 20, 2, 40}, {9, 10, 20, 30, 22}, Mesh -> True]
Out[6]=

View a cross recurrence plot of a range and a short list of integers:

In[7]:=
ResourceFunction["CrossRecurrencePlot"][
 Range[10], {1, 0, 2, 0, 3, 0, 4, 0, 5, 0}]
Out[7]=

View the cross recurrence plot of discrete values of Sin and Cos:

In[8]:=
ResourceFunction["CrossRecurrencePlot"][
 Table[Sin[x], {x, -10, 10, .2}], Table[Cos[x], {x, -10, 10, .2}]]
Out[8]=

View a cross recurrence plot of two lists of different sizes :

In[9]:=
ResourceFunction["CrossRecurrencePlot"][Range[10], Table[x, {x, -10, 10, 1}]]
Out[9]=

Applications

We can analyse time series behaviour by cross recurrence plots. In this case we combine sine and cosine to create and visualize two different time series:

In[10]:=
Manipulate[GraphicsGrid[{{ListLinePlot[{
      s1 = Table[Sin[x f1x]*Cos[x f1y], {x, -10, 10, .1}],
      s2 = Table[Sin[y f2x]*Cos[y f2y], {y, -10, 10, .1}]}],
    ResourceFunction["CrossRecurrencePlot"][s1, s2, Frame -> None]}}],
 {f1x, 1, 10},
 {f1y, 1, 10},
 {{f2x, 5}, 1, 10},
 {{f2y, 7}, 1, 10}]
Out[10]=

To compare and analyse the dynamical behaviour of two elementary cellular automata rules we can plot them, count the total number of black cells by steps, and them show the global cross recurrence plot. Note that when we select the same rule for the two cellular automata, we see diagonal symmetry:

In[11]:=
Manipulate[SeedRandom[92177];
 init = RandomInteger[1, 100];
 GraphicsGrid[{{ArrayPlot[ca1 = CellularAutomaton[rule1, init, 100], Frame -> None],
    ArrayPlot[ca2 = CellularAutomaton[rule2, init, 100], Frame -> None]},
   {ListLinePlot[{
      ca1dynamics = Total[Transpose[ca1]],
      ca2dynamics = Total[Transpose[ca2]]}],
    ResourceFunction["CrossRecurrencePlot"][ca1dynamics, ca2dynamics, Frame -> None, RecurrenceType -> "Global", ColorFunction -> Hue]}}],
 {{rule1, 30}, 0, 255, 1},
 {{rule2, 110}, 0, 255, 1}]
Out[11]=

Resource History

Source Metadata