# Running Code Everytime (Plots.jl) Package is Loaded?

**URL:** <https://discourse.julialang.org/t/running-code-everytime-plots-jl-package-is-loaded/102880>\
**Category:** General Usage\
**Tags:** package\
**Created:** [August 16, 2023, 8:54pm UTC](https://discourse.julialang.org/t/running-code-everytime-plots-jl-package-is-loaded/102880 "2023-08-16T20:54:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [August 16, 2023, 8:54pm UTC](https://discourse.julialang.org/t/running-code-everytime-plots-jl-package-is-loaded/102880/1 "2023-08-16T20:54:03Z")

</div>

I find that for certain packages there are things I do everytime I am using the package.

For example, in Plots.jl I usually set the default linewidth to 2 via

```julia
using Plots
default(linewidth=2)

```

Is there some way to set my Julia environment up so that everytime I load plots via `using Plots`, I will automatically run `default(linewidth=2)` as well?

Another important thing would be enabling compiled execution for functions from Base when using Debugger.jl. VSCode does this by default, and it would be nice to make my REPL do the same by default.

I am aware of the startup.jl file, but I don’t want to load Plots.jl and Debugger.jl in every REPL session.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 16, 2023, 9:16pm UTC](https://discourse.julialang.org/t/running-code-everytime-plots-jl-package-is-loaded/102880/2 "2023-08-16T21:16:25Z")

</div>

> [@leespen1](#):
>
> Is there some way to set my Julia environment up so that everytime I load plots via `using Plots`, I will automatically run `default(linewidth=2)` as well?

As [explained on stackoverflow](https://stackoverflow.com/questions/65530265/how-to-set-the-default-attributes-of-plots) and in the [Plots documentation](https://docs.juliaplots.org/latest/install/#Initialize), you can simply add:

```julia-auto
PLOTS_DEFAULTS = Dict(:linewidth => 2)

```

to your `startup.jl` file.

More generally, even if Plots.jl didn’t support such a convenient mechanism for overriding defaults, you could create a mini-package MyPlots of the form:

```julia-auto
module MyPlots

using Reexport
@reexport using Plots

function __init__ ()
    default(linewidth=2)
end

end

```

and then do `using MyPlots` instead of `using Plots` in order to load Plots with whatever custom initialization you want.

---

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [August 16, 2023, 10:00pm UTC](https://discourse.julialang.org/t/running-code-everytime-plots-jl-package-is-loaded/102880/3 "2023-08-16T22:00:58Z")

</div>

Thanks!

I saw your first suggestion as a solution on another discourse post, but I misunderstood and thought that I was then supposed to supply `PLOTS_DEFAULTS` as an argument to each plotting call, which would be cumbersome.
