wannesm / dtaidistance

Time series distances: Dynamic Time Warping (fast DTW implementation in C)
Other
1.08k stars 184 forks source link

How to change the DPI and the layout of the output graph? #152

Closed ZihanChen1995 closed 2 years ago

ZihanChen1995 commented 2 years ago

Hi, thank you so much for the great library! May I ask a question about saving the graphs with wrapped paths? As you showed in the example, we can save the visualization as the PNG file with:

s1 = np.array([0., 0, 1, 2, 1, 0, 1, 0, 0, 2, 1, 0, 0])
s2 = np.array([0., 1, 2, 3, 1, 0, 0, 0, 2, 1, 0, 0, 0])
path = dtw.warping_path(s1, s2)
dtwvis.plot_warping(s1, s2, path, filename="warp.png")

But the saved picture looks blurry. May I ask can I increase the DPI or change the layout (side-by-side) of the graph? For example, with matplotlib we can do that with the following to change the size and resolution, can we do the same thing here? Thank you so much in advance!

from matplotlib.pyplot import figure
figure(figsize=(12, 10), dpi=90)
wannesm commented 2 years ago

The plot_warping method returns the Figure object it is using to draw if you don't pass the filename:

fig, axs = dtwvis.plot_warping(s1, s2, path)
fig.set_size_inches(12, 10)
fig.set_dpi(90)
fig.savefig('warp.png')

In the latest commit 0a566f1c33b75b1d791070d27883e9f46ab0a39e , you can also pass in your own Figure object using the fig and axs arguments.

ZihanChen1995 commented 2 years ago

Great! Thank you so much @wannesm , it works perfectly now. Have a wonderful weekend!