Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in plotting #191

Open
gg4u opened this issue Apr 3, 2023 · 1 comment
Open

error in plotting #191

gg4u opened this issue Apr 3, 2023 · 1 comment

Comments

@gg4u
Copy link

gg4u commented Apr 3, 2023

I tried:

from dtaidistance import clustering
# Custom Hierarchical clustering
model1 = clustering.Hierarchical(dtw.distance_matrix_fast, {})
cluster_idx = model1.fit(series)
# Augment Hierarchical object to keep track of the full tree
model2 = clustering.HierarchicalTree(model1)
cluster_idx = model2.fit(series)
# SciPy linkage clustering
model3 = clustering.LinkageTree(dtw.distance_matrix_fast, {})
cluster_idx = model3.fit(series)

and

model3.plot()

but error:


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[153], line 1
----> 1 model3.plot()

File /data0/home/h21/luas6629/venv/lib/python3.10/site-packages/dtaidistance/clustering/hierarchical.py:383, in BaseTree.plot(self, filename, axes, ts_height, bottom_margin, top_margin, ts_left_margin, ts_sample_length, tr_label_margin, tr_left_margin, ts_label_margin, show_ts_label, show_tr_label, cmap, ts_color)
    380         cnt_ts = plot_i(child_right, depth + 1, cnt_ts, prev_lcnt + clcntr, ax, False)
    381     return cnt_ts
--> 383 plot_i(self.maxnode, 0, 0, node_props[self.maxnode][2], ax, True)
    385 if filename:
    386     if isinstance(filename, Path):

File /data0/home/h21/luas6629/venv/lib/python3.10/site-packages/dtaidistance/clustering/hierarchical.py:366, in BaseTree.plot.<locals>.plot_i(node, depth, cnt_ts, prev_lcnt, ax, left)
    364 ax[0].add_line(Line2D((px, px), (py, cy), lw=1, color=color, axes=ax[0]))
    365 ax[0].add_line(Line2D((px, cx), (cy, cy), lw=1, color=color, axes=ax[0]))
--> 366 cnt_ts = plot_i(child_left, depth + 1, cnt_ts, prev_lcnt - crcntl, ax, True)
    368 # Right
    369 ccnt, cdepth, clcntr, crcntr, crcdist = node_props[child_right]

File /data0/home/h21/luas6629/venv/lib/python3.10/site-packages/dtaidistance/clustering/hierarchical.py:366, in BaseTree.plot.<locals>.plot_i(node, depth, cnt_ts, prev_lcnt, ax, left)
    364 ax[0].add_line(Line2D((px, px), (py, cy), lw=1, color=color, axes=ax[0]))
    365 ax[0].add_line(Line2D((px, cx), (cy, cy), lw=1, color=color, axes=ax[0]))
--> 366 cnt_ts = plot_i(child_left, depth + 1, cnt_ts, prev_lcnt - crcntl, ax, True)
    368 # Right
    369 ccnt, cdepth, clcntr, crcntr, crcdist = node_props[child_right]

File /data0/home/h21/luas6629/venv/lib/python3.10/site-packages/dtaidistance/clustering/hierarchical.py:366, in BaseTree.plot.<locals>.plot_i(node, depth, cnt_ts, prev_lcnt, ax, left)
    364 ax[0].add_line(Line2D((px, px), (py, cy), lw=1, color=color, axes=ax[0]))
    365 ax[0].add_line(Line2D((px, cx), (cy, cy), lw=1, color=color, axes=ax[0]))
--> 366 cnt_ts = plot_i(child_left, depth + 1, cnt_ts, prev_lcnt - crcntl, ax, True)
    368 # Right
    369 ccnt, cdepth, clcntr, crcntr, crcdist = node_props[child_right]

File /data0/home/h21/luas6629/venv/lib/python3.10/site-packages/dtaidistance/clustering/hierarchical.py:343, in BaseTree.plot.<locals>.plot_i(node, depth, cnt_ts, prev_lcnt, ax, left)
    341     else:
    342         curcolor = None
--> 343     line, = ax[1].plot(ts_left_margin + ts_sample_length * np.arange(len(serie)),
    344                        bottom_margin + ts_height * (cnt_ts + 0.5) + self.ts_height_factor * serie,
    345                        color=curcolor)
    346     cnt_ts += 1
    348 else:

ValueError: too many values to unpack (expected 1)

Can you show example ?

How does the library handle audio files as well, for computing DTW between audio ?
I tried to compute DTW and works fine, but plotting seems an issue, also plotting the "mapping" of audio large numpy series reflecting the audio (from librosa).

@bramiozo
Copy link

bramiozo commented Apr 9, 2023

This should fix it: #192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants