Open CiaranOMara opened 4 years ago
I can make the above example work like so:
using Gadfly, Gadfly.Stat.KernelDensity
Gadfly.evalmapping(source::UnivariateKDE, arg::Function) = arg(source)
Gadfly.evalmapping(source::UnivariateKDE, arg::Symbol) = getfield(source, arg)
maximum_density(d::UnivariateKDE) = [d.x[argmax(d.density)]]
data = randn(100)
plot(kde(data), x=:x, y=:density, Geom.line, xintercept=maximum_density, Geom.vline(color="blue"))
At the moment I think the two evalmapping
functions here are a bit specific for Gadfly, but I welcome other people's input.
It would be good to put an example of this in the Gadly docs (perhaps in a section Advanced Gadfly - Plotting custom types).
let's definitely document this. that's pretty cool!
When I set up a plot in Gadfly, I typically need to map data from a
struct
, I found that I can extendGadfly.evalmaping
to avoid writing wrappers.However, not all geometries can handle mappings of functions.
While I know that in this case, it is trivial to evaluate
kde(data)
in an outside scope, its result is not always something that I'd want to keep in that scope.