Using Plots.jl within a package _iteratively_

Thank you for the suggestion. I’ve reviewed the docs for RecipiesBase again, but I’m still not clear on how this solves my problem. I want to call the plot function from within my package to generate plots as the algorithm is running, on-the-fly. In contrast, it seems that recipies are designed to tell the plot function how to plot a new type of data – kinda-like defining a plot method but without requiring the Plots package. Please do correct me if I’m misunderstanding this.

I’m less interested in generating a custom type of plot and more interested in how to just run the plot function from within my package. I’m thinking of just having my optimization function take an optional argument of type Function so that I can pass-in plot as a way to inject it. Something like

function optimize(x, plot_function::Union{Function, nothing})
  ...
  for i in 1:max_iter
    x = update_x(x)
    if !isnothing(plot_function)
      plot_function(x)
    end
  end
end