JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.82k stars 350 forks source link

RFC: Modifying the recipe system to allow for custom argument conversions #2144

Open asinghvi17 opened 5 years ago

asinghvi17 commented 5 years ago

Something pretty useful that's defined in Makie is the ability to define argument conversions (by arguments I mean positional arguments here) on (in Plots terms) a per-series basis. So, for example, you could define one argument conversion for your custom type for lines, and another for mesh.
However, as far as I'm aware, in Plots that can't be done generically, since "type recipes" are applied before the series decomposition takes place. What I'm proposing here is to add a new recipe type which would be applied at the time of series decomposition, so that the user could return any type which has a one-to-one conversion into a plottable type from an @series block in a recipe, and have that "just work" - i.e., you could return a DiffEqArray from a @series invocation in which a differential equation is solved, and then have that converted into vectors using the type recipe which is defined.

Or, you could - and again this is an example here - define a conversion between your own type and a matrix, specifically for the corrplot recipe, which would be applied before applying the user recipe.

This recipe type would probably have syntax resembling:

@recipe function f(::Val{:series_or_userplot_name}, ::Type{MyType}, ::MyType; kwargs...)
    # your function here
    # return some type which can be plotted, or converted to plottable recursively
    # Note that subplot specification and layouting should be disallowed here
end

I would love to help implement this, if it's decided that this is a feature we should have in Plots.

asinghvi17 commented 5 years ago

cc @mkborregaard @piever