# Eror UndefVarError: plot not defined

**URL:** <https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936>\
**Category:** General Usage\
**Tags:** ode\
**Created:** [June 4, 2019, 9:08pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936 "2019-06-04T21:08:24Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.julialang.org/u/math)\
**Post date:** [June 4, 2019, 9:08pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/1 "2019-06-04T21:08:24Z")

</div>

I am getting this error: UndefVarError: plot not defined

Here is my code:

```julia
# Packages
using Pkg
#using Plots
using DifferentialEquations
using PyPlot

# Parameters
i = 1.25 # 0.089;%nutrient input HG 4.5 gram per 4 days, LG 1 gram per four days, on fourth day 4/45/4=1.25
f = .25 #0.0015; %nutrient removal, I/f = 50? 100% every four days=.25 per day
u = .4#uptake by X red
w = 1.14 #1.14;%uptake by green
a = 1.19 # growth rate for red X is ln(2)*24/14
d = .25 #.005;%death of P red
s = .02 #10;%numerical half saturation X uptake red, controls passage to quiescence
b = 0.55 # growth rate for green Y is ln(2)*24/30
e = .15 #death of Q green 
r = 5 #numerical half saturation Y uptake green
m = 0 #.05;0 when looking at single pop
q = .00001
h =1 # return loop P to X
v = .03 # half saturation for return loop P to X

# Time
maxtime = 30
tspan = (0.0, maxtime)

# Dose
stim = 50

# Initial conditions
x0 = [100 1 20.0 200.0 200.0]

# Model equations
function system(dy, y, p, t)

V = y[1]
X = y[2]
Y = y[3]
P = y[4]
Q = y[5]

V, X, Y, P, Q, = y
T = X+Y
E = (V)./(v+T+V)
A = (V)./(s+V)
B = (V)./(r+T+V)
C = X./(X+Y+q)
D = Y./(X+Y+q)

  dy[1] = i - f.*V - u.*X.*A- w.*Y.*B
  dy[2] = a.*X.*A - a.*X.*(1-A) + m.*P - m.*P.*C + h.*P.*E
  dy[3] = b.*Y.*B -e.*Y - b.*Y.*(1-B) - m.*P.*D
  dy[4] = a.*X.*(1-A) - m.*P + m.*P.*C - d.*P - h.*P.*E
  dy[5] = b.*Y.*(1-B) + m.*P.*D - e.*Q
end

# Events
function condition1(y, t, integrator)
    t - 6.0
end
function condition2(y, t, integrator)
    t-20.0
end

function affect!(integrator)
    integrator.u[1] += stim
end

cb1 = ContinuousCallback(condition1, affect!)
cb2 = ContinuousCallback(condition2, affect!)
cb = CallbackSet(cb1,cb2)
# Solve
prob = ODEProblem(system, x0, tspan)
sol = solve(prob, Rodas4(), callback = cb)

# Plotting
#plot(sol, layout = (2, 3))
legends = [:V :X :Y :P :Q]
#linetypes = = [:path :steppre :steppost :sticks :scatter]
#plot(sol, line=(linetypes, 3), background_color=RGB(0.2, 0.2, 0.2), layout = (2, 3), #xlim=(0, 10), label=map(string, legends))

plot(sol, vars=(0,4),background_color=RGB(0.2, 0.2, 0.2), xaxis="Time",label = "P", lw=3,ls=:dash)

#xlabel(''Time (days)'')
# title!("TITLE")
# yaxis!("YLABEL", :log10)

```

UPDATE: I ran it again after posting this question and I got another error: UndefVarError: RGB not defined. I am not sure what’s going on.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 4, 2019, 9:22pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/2 "2019-06-04T21:22:59Z")

</div>

> [@math](#):
>
> plot(sol, vars=(0,4)

That syntax is only for Plots.jl. It looks like you’re not using Plots.jl, so you need to construct the plotting vectors manually.

---

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.julialang.org/u/math)\
**Post date:** [June 4, 2019, 9:23pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/3 "2019-06-04T21:23:48Z")

</div>

How can I use plots.jl?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [June 4, 2019, 9:25pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/4 "2019-06-04T21:25:47Z")

</div>

```julia
using Plots

```

---

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.julialang.org/u/math)\
**Post date:** [June 4, 2019, 9:27pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/5 "2019-06-04T21:27:52Z")

</div>

I tried that earlier and got this error:

```julia
WARNING: both PyPlot and Plots export "plot"; uses of it in module Main must be qualified

**ERROR:** LoadError: UndefVarError: plot not defined

Stacktrace:

[1] top-level scope at **none:0**

[2] **include** at **./boot.jl:326** [inlined]

[3] **include_relative(** ::Module, ::String **)** at **./loading.jl:1038**

[4] **include(** ::Module, ::String **)** at **./sysimg.jl:29**

[5] **include(** ::String **)** at **./client.jl:403**

[6] top-level scope at **none:0**

in expression starting at

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [June 4, 2019, 9:28pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/6 "2019-06-04T21:28:23Z")

</div>

Delete the line `using PyPlot`.

---

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.julialang.org/u/math)\
**Post date:** [June 4, 2019, 9:29pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/7 "2019-06-04T21:29:26Z")

</div>

Tried that as well. Here is the error:

```julia
**ERROR:** LoadError: UndefVarError: plot not defined

Stacktrace:

```

---

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.julialang.org/u/math)\
**Post date:** [June 4, 2019, 9:36pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/8 "2019-06-04T21:36:23Z")

</div>

Also, I closed and reopened the terminal, ran the file again and got this error:

```julia
**ERROR:** LoadError: error compiling _plot!: error compiling _display: could not load library "libGR.so"

dlopen(libGR.so.dylib, 1): image not found

```

The error message changes everytime and that’s what’s more confusing. Is there a free GUI that I could use for Julia?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 4, 2019, 9:55pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/9 "2019-06-04T21:55:49Z")

</div>

Try `]build Plots`. Looks like the plot library did not build probably on your computer.

---

<div class="post-metadata">

**Author:** ![kamalojasv181](https://avatars.discourse-cdn.com/v4/letter/k/4bbf92/32.png) [@kamalojasv181](https://discourse.julialang.org/u/kamalojasv181)\
**Post date:** [March 3, 2020, 3:16am UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/10 "2020-03-03T03:16:18Z")

</div>

@ChrisRackauckas that did not help

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 3, 2020, 4:53am UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/11 "2020-03-03T04:53:26Z")

</div>

I’d have to know what code you’re running and what error you got. It’s likely not related to this issue.

---

<div class="post-metadata">

**Author:** ![Murad1997](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Murad1997](https://discourse.julialang.org/u/Murad1997)\
**Post date:** [May 31, 2020, 11:46pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/12 "2020-05-31T23:46:51Z")

</div>

May be try using Plots.plot ???

---

<div class="post-metadata">

**Author:** ![Xixi](https://avatars.discourse-cdn.com/v4/letter/x/b5a626/32.png) [@Xixi](https://discourse.julialang.org/u/Xixi)\
**Post date:** [June 16, 2020, 12:46pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/13 "2020-06-16T12:46:48Z")

</div>

It works! Thanks!

---

<div class="post-metadata">

**Author:** ![lwhitefox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lwhitefox/32/4363_2.png) [@lwhitefox](https://discourse.julialang.org/u/lwhitefox)\
**Post date:** [July 31, 2020, 8:22pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/14 "2020-07-31T20:22:44Z")

</div>

Quick note in case someone is monitoring this - I also had the error:

```julia
julia> plot(f)
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: could not load library "libGR.so"
dlopen(libGR.so.dylib, 1): image not found

```

But it was very odd, because I’ve been happily plotting regularly in several local project environments. The only difference was I set up a new project environment with only Plots and Zygote added - but I could only plot after doing the manual build (`pkg> build Plots`). Weird.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 31, 2020, 11:18pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/15 "2020-07-31T23:18:51Z")

</div>

Sometimes you lose internet when the binary is downloading and that could cause this problem.

---

<div class="post-metadata">

**Author:** ![PedroPizarro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pedropizarro/32/216074_2.png) [@PedroPizarro](https://discourse.julialang.org/u/PedroPizarro)\
**Post date:** [August 14, 2020, 12:30am UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/16 "2020-08-14T00:30:57Z")

</div>

Worked here! I’ve just restarted the jupyter and run the cells again, perfection.

---

<div class="post-metadata">

**Author:** ![Ian-GB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ian-gb/32/34644_2.png) [@Ian-GB](https://discourse.julialang.org/u/Ian-GB)\
**Post date:** [March 17, 2022, 5:43pm UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/17 "2022-03-17T17:43:39Z")

</div>

Not sure this was the issue, but it might have been for me when I got this error, and it might help someone else, 2 years after the birth of this thread.

Sometimes it is probably better to call libraries with `import Plots` and then call the functions with `Plots.plot()` rather than with `using Plots` and then calling them with `plot()` because there may be conflicts between different functions (belonging to different libraries) which bear the same name.

---

<div class="post-metadata">

**Author:** ![Amelius258](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amelius258/32/43573_2.png) [@Amelius258](https://discourse.julialang.org/u/Amelius258)\
**Post date:** [October 15, 2022, 9:40am UTC](https://discourse.julialang.org/t/eror-undefvarerror-plot-not-defined/24936/18 "2022-10-15T09:40:36Z")

</div>

which exactly works in my case, many thanks!
