# Using Plots.jl within a package \_iteratively\_

**URL:** <https://discourse.julialang.org/t/using-plots-jl-within-a-package-iteratively/33852>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [January 27, 2020, 3:10pm UTC](https://discourse.julialang.org/t/using-plots-jl-within-a-package-iteratively/33852 "2020-01-27T15:10:18Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [January 28, 2020, 2:44pm UTC](https://discourse.julialang.org/t/using-plots-jl-within-a-package-iteratively/33852/3 "2020-01-28T14:44:06Z")

</div>

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

```julia
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

```

---

_[View the full topic](https://discourse.julialang.org/t/using-plots-jl-within-a-package-iteratively/33852)._
