Visualization#
- thebeat.visualization.phase_space_plot(sequence, linecolor='black', linewidth=0.5, title=None, x_axis_label='$\\\\mathregular{IOI_t}$', y_axis_label='$\\\\mathregular{IOI_{t+1}}$', figsize=None, dpi=100, ax=None)[source]#
Plot the phase space of a sequence. In such a plot we loop over each IOI, and plot a line between it on the x axis and the IOI that follows it on the y axis.
- Parameters:
sequence (
Sequence) – The sequence to plot.linecolor (
str, default:'black') – The color of the lines.linewidth (
float, default:0.5) – The width of the lines.x_axis_label (
str, default:'$\\\\mathregular{IOI_t}$') – The label for the x axis.y_axis_label (
str, default:'$\\\\mathregular{IOI_{t+1}}$') – The label for the y axis.figsize (
tuple[int,int] |None, default:None) – The size of the figure to be created in inches, width x height, e.g. (4, 4).dpi (
int, default:100) – The resolution of the figure in dots per inch.ax (
Axes|None, default:None) – An optional matplotlibAxesobject to plot on. If not provided, a new Axes object will be created. If anAxesobject is provided, this function returns the originalFigureandAxesobjects.
- Return type:
Example
Example of a phase space plot.#
Note
Code adapted from Ravignani and Norton [RN17].
Examples
>>> from thebeat import Sequence >>> seq = Sequence.generate_random_normal(100,100,10) >>> phase_space_plot(seq)
- thebeat.visualization.plot_interval_ratios_density(sequence, resolution=0.01, title=None, x_axis_label='Interval ratios from dyads', y_axis_label='Probability density', figsize=None, dpi=100, ax=None)[source]#
Plot a density plot of the interval ratios from sequential dyads in a sequence. Input can either be a single sequence, or a list or array of sequences.
This function internally uses
thebeat.utils.get_interval_ratios_from_dyads()to calculate the interval ratios.Example
Example interval ratios density plot.#
- Parameters:
sequence (
Sequence|list[Sequence] |ndarray[Sequence]) – The sequence or list or array of sequences to plot.resolution (
float, default:0.01) – The resolution of the density plot. At each point, the probability density is calculated.x_axis_label (
str, default:'Interval ratios from dyads') – The label for the x axis.y_axis_label (
str, default:'Probability density') – The label for the y axis.figsize (
tuple[int,int] |None, default:None) – The size of the figure to be created in inches, width x height, e.g. (4, 4).dpi (
int, default:100) – The resolution of the figure in dots per inch.ax (
Axes|None, default:None) – An optional matplotlibAxesobject to plot on. If not provided, a new Axes object will be created. If anAxesobject is provided, this function returns the originalFigureandAxesobjects.
- Return type:
- thebeat.visualization.plot_interval_ratios_histogram(sequence, bins=100, title=None, x_axis_label='Interval ratios from dyads', y_axis_label='Count', figsize=None, dpi=100, ax=None)[source]#
Plot a histogram of the interval ratios from sequential dyads in a sequence. Input can either be a single sequence, or a list or array of sequences.
This function internally uses
thebeat.utils.get_interval_ratios_from_dyads()to calculate the interval ratios.Example
Example interval ratios histogram.#
- Parameters:
sequence (
Sequence|list[Sequence] |ndarray[Sequence]) – The sequence or list or array of sequences to plot.bins (
int, default:100) – The number of bins to use in the histogram.x_axis_label (
str, default:'Interval ratios from dyads') – The label for the x axis.y_axis_label (
str, default:'Count') – The label for the y axis.figsize (
tuple[int,int] |None, default:None) – The size of the figure to be created in inches, width x height, e.g. (4, 4).dpi (
int, default:100) – The resolution of the figure in dots per inch.ax (
Axes|None, default:None) – An optional matplotlibAxesobject to plot on. If not provided, a new Axes object will be created. If anAxesobject is provided, this function returns the originalFigureandAxesobjects.
- Return type:
- thebeat.visualization.plot_multiple_sequences(sequences, title=None, x_axis_label='Time', y_axis_labels=None, linewidths=None, figsize=None, dpi=100, colors=None, ax=None)[source]#
Plot multiple sequences in one plot. Either pass it a list or array of
Sequenceobjects,SoundSequenceobjects, or list or array of event onsets (so e.g. list of lists).- Parameters:
sequences (
list|ndarray) – A list or array ofSequenceorSoundSequenceobjects. Alternatively, one can provide e.g. a list of lists containing event onsets, for instance:[[0, 500, 1000], [0, 600, 800], [0, 400, 550]].x_axis_label (
str, default:'Time') – A label for the x axis.y_axis_labels (
list[str] |ndarray[str] |None, default:None) – A list or array containing names for the sequences as strings. For instance['Sequence 1', 'Sequence 2']etc. Must be of the same length as the number of sequences passed. If no names are provided, defaults to numbering the sequences. This is because matplotlib needs a label there.title (
str|None, default:None) – If desired, one can provide a title for the plot. This takes precedence over using the Sequence or SoundSequence name as the title of the plot (if passed and the object has one).linewidths (
list[float] |ndarray[tuple[Any,...],dtype[float]] |float|None, default:None) – An array or list of ints (e.g.[50, 50, 50]) or nested array or list containing the desired widths of the bars (event durations), for instance:[[50, 30, 60], [20, 40, 10], [60, 30, 10]]. By default, ifSoundSequenceobjects are passed, the event durations are used. In other cases, a default of 1/10th of the smallest IOI is used.figsize (
tuple|None, default:None) – A tuple containing the desired output size of the plot in inches, e.g.(4, 1). This refers to thefigsizeparameter inmatplotlib.pyplot.figure().dpi (
int, default:100) – The resolution of the plot in dots per inch. This refers to thedpiparameter inmatplotlib.pyplot.figure().colors (
list|ndarray, default:None) – A list or array of colors to use for the plot. If not provided, the default matplotlib colors are used. Colors may be provided as strings (e.g.'red') or as RGB tuples (e.g.(1, 0, 0)).ax (
Axes|None, default:None) – If desired, you can provide an existingmatplotlib.axes.Axesobject onto which to plot. See the Examples of the different plotting functions to see how to do this (e.g.plot_sequence()). If an existingmatplotlib.axes.Axesobject is supplied, this function returns the originalmatplotlib.figure.Figureandmatplotlib.axes.Axesobjects.
- Return type:
Examples
>>> from thebeat.core import Sequence >>> generator = np.random.default_rng(seed=123) >>> seqs = [Sequence.generate_random_normal(n_events=5,mu=5000,sigma=50,rng=generator) for _ in range(10)] >>> plot_multiple_sequences(seqs,linewidths=50)
>>> seq1 = Sequence([500, 100, 200]) >>> seq2 = Sequence([100, 200, 500]) >>> fig, ax = plot_multiple_sequences([seq1, seq2],colors=['red', 'blue']) >>> fig.savefig('test.png')
- thebeat.visualization.plot_phase_differences(test_sequence, reference_sequence, reference_ioi='preceding', window_size=None, modulo=True, circular_unit='degrees', binwidth=10, zero_direction='E', color=None, title=None, figsize=None, dpi=100, ax=None)[source]#
Plot the phase differences for
test_sequencecompared toreference_sequence.The reference sequence can either be a single sequence in which case a comparison will be made between each test sequence and the reference sequence, or a float in which case a comparison will be made between each test sequence and an isochronous sequence with the provided IOI, or it can be an array or list of sequences, in which case a comparison is made between each test and reference sequence element-wise.
Example
Example phase differences plot.#
- Parameters:
test_sequence (
Sequence) – A sequence or a single time point to be compared with the reference sequence. Can either be a single event time, or a Sequence, list, or NumPy array containing multiple events.reference_sequence (
Sequence) – The reference sequence. Can be a Sequence object, a list or array of Sequence objects, or a number. In the latter case, the reference sequence will be an isochronous sequence with a constant IOI of that number and the same length assequence_1.reference_ioi (
str, default:'preceding') – The IOI in the reference sequence that is used as the reference IOI. Can be either “containing” or “preceding”.window_size (
int|None, default:None) – The window size used for calculating the mean reference IOI. Only used ifreference_ioi='preceding'.modulo (
bool, default:True) – Return the phase differences modulo 360 degrees or not. Only has an effect ifreference_ioi='preceding'.circular_unit (
str, default:'degrees') – The unit of the circular data. Can be ‘degrees’ or ‘radians’.binwidth (
int, default:10) – The width of the bins used to calculate the histogram bars.zero_direction (
str, default:'E') – The direction of the zero angle. Can be ‘N’, ‘E’, ‘S’, or ‘W’.color (
str, default:None) – The color of the bars. Can be a single color or a list of colors, one for each bar. Seematplotlib.axes.Axes.bar()for more information.figsize (
tuple[int,int] |None, default:None) – The size of the figure to be created in inches.dpi (
int, default:100) – The resolution of the figure in dots per inch.ax (
Axes|None, default:None) – An optionalmatplotlib.axes.Axesobject to plot on. If not provided, a new Axes object will be created. If anmatplotlib.axes.Axesobject is provided, the function returns the originalmatplotlib.figure.Figureandmatplotlib.axes.Axesobjects.
- Return type:
- thebeat.visualization.recurrence_plot(sequence, threshold=None, colorbar=False, colorbar_label='Distance', cmap=None, title=None, x_axis_label='$\\\\mathregular{N_i}$', y_axis_label='$\\\\mathregular{N_i}$', figsize=(5, 4), dpi=100, ax=None)[source]#
Plot a recurrence plot of a sequence. A recurrence plot is a plot with the IOI numbers (i.e. their indices) on the x and y axis, and the distance between the IOIs on the color scale. For each combination of two IOIs, the distance between these IOIs is calculated as their absolute difference (which may for instance be in seconds or milliseconds, depending on your input during construction of the
Sequenceobject).If you provide a
threshold, the plot will be binary, where color indicates anything below the threshold, and where white indicates anything above the threshold.Example
Example recurrence plot with
colorbar=True.#- Parameters:
threshold (
float|None, default:None) – The threshold to use for the recurrence plot. If a threshold is given, the plot is binary, with color (e.g. black) representing the inter-onset intervals that are below the threshold. If no threshold is given, the plot is colored according to the distance between the inter-onset intervals.colorbar (
bool, default:False) – IfTrue, a colorbar is added to the plot. Note that no colorbar is plotted when an existing Axes object is provided.colorbar_label (
str|None, default:'Distance') – A label for the colorbar.cmap (
str|None, default:None) – The colormap to use for the plot. See matplotlib colormaps reference for the different options. For binary plots, the default is'Greys', for colored plots, the default is'viridis'.title (
str|None, default:None) – If desired, one can provide a title for the plot.x_axis_label (
str, default:'$\\\\mathregular{N_i}$') – A label for the x axis.y_axis_label (
str, default:'$\\\\mathregular{N_i}$') – A label for the y axis.figsize (
tuple, default:(5, 4)) – A tuple containing the desired output size of the plot in inches, e.g.(4, 1).dpi (
int, default:100) – The resolution of the plot in dots per inch.ax (
Axes|None, default:None) – If desired, you can provide an existingmatplotlib.axes.Axesobject onto which to plot. See the Examples of the different plotting functions to see how to do this (e.g.plot_sequence()). If an existingmatplotlib.axes.Axesobject is supplied, this function returns the originalmatplotlib.figure.Figureandmatplotlib.axes.Axesobjects.
- Return type:
Examples
>>> from thebeat.core import Sequence >>> from thebeat.visualization import recurrence_plot >>> seq = Sequence.generate_random_normal(n_events=3,mu=5000,sigma=50,end_with_interval=True) * 10 >>> recurrence_plot(seq)
>>> fig, ax = recurrence_plot(seq, dpi=300, colorbar=True) >>> fig.savefig('recurrence_plot.png', bbox_inches='tight')
>>> seq = Sequence.generate_random_normal(n_events=3,mu=5000,sigma=50,end_with_interval=True) * 10 >>> fig, ax = recurrence_plot(seq, threshold=5, dpi=300) >>> fig.savefig('recurrence_plot.png')
Notes
The binary recurrence plot is based on Ravignani and Norton [RN17]. The coloured recurrence plot is based on Burchardt et al. [BBKnornschild21].