Understanding recipes in Plots.jl

Oh, this is just a standard Julia design. Instead of writing two different implementations when you have a mutating function, you just make the non-mutating version pass to the mutating version.

f!(y,x) # does something mutating to x
function f(x) 
  y = similar(x)
  f!(y,x)
  y
end

This is a very common structure in Julia because mutating allows things to be faster, and sometimes allows more functionality. So for plot recipes, the implementation is really just plot!(dispatch_type,plot, args...) which adds a new dispatch_type recipe to an existing plot. This style of using dispatch on types to add extend functionality to a common function call is described here:

So then the out-of-place plot silently adds in the current plot and calls plot! and continues. So what you’re really defining is a new plot! function with a new type, where the first argument is a type which controls its dispatch. Make sense?

But this page describes all of the customization options, does it not?

https://juliaplots.github.io/attributes/

But I think what you’re looking for is more of an “Introduction to Plots”. I think a package manual should go through all of the details and explain everything it can do, which is what the docs currently do. A separate thing would be a quicker “Dive Into Plots”, and someone should write something like that.

The easiest way is to ask a question, and once it makes sense, make a PR for the docs.

3 Likes