org-arl / SignalAnalysis.jl

Signal analysis toolbox for Julia
MIT License
41 stars 10 forks source link

plot functions #1

Closed baggepinnen closed 4 years ago

baggepinnen commented 4 years ago

I noticed that the plot recipes have been converted to functions in the dev branch. I assume (correct me if I'm wrong) that this has to do with the uncomfort associated with argument handling and dispatch in recipes?

A typical solution to this problem is to have all the functions return special types, such as Spectrogram/PSD etc. and define recipes for how to plot those. The call would then look like plot(specgram(args...)).

Unless there is a strong reason to have plot functions rather than recipes, recipes are quite nice when you want to add to existing plots and compose plots etc. The plot=plot! strategy only works if you want to add to the last plot, for example, the following would not work

f1 = plot()
f2 = plot()
for i in 1:10
    plot!(f1, ...)
    plot!(f2, ...)
end
mchitre commented 4 years ago

Nothing to do with the discomfort, but rather that the data types I want to deal with are often generic (arrays) and therefore unavailable for dispatch. I don't want to artificially have to wrap them just for dispatch, and therefore prefer the function name to differentiate between the type of plot. Noted the example you have above, which is easily manageable with an additional argument, but will take a look at the user plot recipes that you suggested yesterday and see if it provides a better way than what I have.

mchitre commented 4 years ago

Moved back to plot recipes as you suggested for all normal plots. Interactive plots are still "special", since I've not yet figured out how to update the plot from within a recipe. If and when I do, I'll update those too.