Skip to content

Commit

Permalink
rewrote dtw advanced example plots
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Jun 25, 2020
1 parent ec2889a commit 2568595
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/examples/plot_chroma.py
Expand Up @@ -24,7 +24,7 @@

# Code source: Brian McFee
# License: ISC
# sphinx_gallery_thumbnail_number = 6
# sphinx_gallery_thumbnail_number = 5

import numpy as np
import scipy
Expand Down
45 changes: 19 additions & 26 deletions docs/examples/plot_music_sync.py
Expand Up @@ -92,37 +92,30 @@
# We can also visualize the warping path directly on our time domain signals.
# Red lines connect corresponding time positions in the input signals.
# (Thanks to F. Zalkow for the nice visualization.)
from matplotlib.patches import ConnectionPatch

fig, (ax1, ax2) = plt.subplots(nrows=2, sharey=True)

# Plot x_1
librosa.display.waveplot(x_1, sr=fs, ax=ax1)
ax1.set(title='Slower Version $X_1$')
fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, sharey=True, figsize=(8, 4))

# Plot x_2
librosa.display.waveplot(x_2, sr=fs, ax=ax2)
ax2.set(title='Slower Version $X_2$')


trans_figure = fig.transFigure.inverted()
lines = []
arrows = 30
points_idx = np.int16(np.round(np.linspace(0, wp.shape[0] - 1, arrows)))
ax2.set(title='Faster Version $X_2$')

# for tp1, tp2 in zip((wp[points_idx, 0]) * hop_length, (wp[points_idx, 1]) * hop_length):
for tp1, tp2 in wp_s[points_idx]:
# get position on axis for a given index-pair
coord1 = trans_figure.transform(ax1.transData.transform([tp1, 0]))
coord2 = trans_figure.transform(ax2.transData.transform([tp2, 0]))

# draw a line
line = matplotlib.lines.Line2D((coord1[0], coord2[0]),
(coord1[1], coord2[1]),
transform=fig.transFigure,
color='r')
lines.append(line)

fig.lines = lines
# Plot x_1
librosa.display.waveplot(x_1, sr=fs, ax=ax1)
ax1.set(title='Slower Version $X_1$')
ax1.label_outer()


n_arrows = 20
for tp1, tp2 in wp_s[::len(wp_s)//n_arrows]:
# Create a connection patch between the aligned time points
# in each subplot
con = ConnectionPatch(xyA=(tp1, 0), xyB=(tp2, 0),
axesA=ax1, axesB=ax2,
coordsA='data', coordsB='data',
color='r', linestyle='--',
alpha=0.5)
ax2.add_artist(con)

###########################################################
# -------------
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/plot_segmentation.py
Expand Up @@ -114,15 +114,15 @@
###########################################################
# Plot the resulting graphs (Figure 1, left and center)
fig, ax = plt.subplots(ncols=3, sharex=True, sharey=True, figsize=(10, 4))
librosa.display.specshow(Rf, cmap='inferno_r', y_axis='time', x_axis='time',
librosa.display.specshow(Rf, cmap='inferno_r', y_axis='time', x_axis='s',
y_coords=beat_times, x_coords=beat_times, ax=ax[0])
ax[0].set(title='Recurrence similarity')
ax[0].label_outer()
librosa.display.specshow(R_path, cmap='inferno_r', y_axis='time', x_axis='time',
librosa.display.specshow(R_path, cmap='inferno_r', y_axis='time', x_axis='s',
y_coords=beat_times, x_coords=beat_times, ax=ax[1])
ax[1].set(title='Path similarity')
ax[1].label_outer()
librosa.display.specshow(A, cmap='inferno_r', y_axis='time', x_axis='time',
librosa.display.specshow(A, cmap='inferno_r', y_axis='time', x_axis='s',
y_coords=beat_times, x_coords=beat_times, ax=ax[2])
ax[2].set(title='Combined graph')
ax[2].label_outer()
Expand Down

0 comments on commit 2568595

Please sign in to comment.