# Understanding basic Plots behavior

**URL:** https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479
**Category:** New to Julia
**Created:** [February 5, 2019, 4:56pm UTC](https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479 "2019-02-05T16:56:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tomf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomf/32/6995_2.png) [@tomf](https://discourse.julialang.org/u/tomf)
#### Post date: [February 5, 2019, 4:56pm UTC](https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479/1 "2019-02-05T16:56:41Z")

</div>

I’m working my way through basic Julia exercises in a course. I have no problem with most of it but I haven’t yet grasped the odd way plots seem to work. Here’s a basic fn for calculating the steady state values of a logistic map:

```julia
function steady_state_values(r)
    b = 0.25
    for i in 1:400
        b = r * b * (1-b)
    end
    attractor_values = zeros(150)
    for i in 1:150
        b = r * b * (1-b)
        attractor_values[i] = b
    end
    return attractor_values
end

```

I want to vary the parameter r (along the x axis) and plot the corresponding steady state values along y. I’ve tried variations of this:

```julia
using Plots
first = true
for r = 2.9 : 0.001 : 4
    y = steady_state_values(r)
    x = fill(r, length(y))
    if first
        plot(x=x, y=y)
        first = false
    else
        plot!(x=x, y=y)
    end
end

```

Multiple calls to plot don’t seem to work–they result in no output-- so I plot the first array then call plot! subsequently. Even this doesn’t work. Can someone explain the logic? I come from matplotlib where you call figure() to begin, then any number of plotting operations, then show().  
Plots.jl doesn’t seem to work that way. I’ve gone through a Plots.jl notebook but it didn’t clarify.

Thanks,  
-Tom

---

<div class="post-metadata">

### Author: ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)
#### Post date: [February 5, 2019, 5:25pm UTC](https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479/2 "2019-02-05T17:25:35Z")

</div>

`plot(...)` creates and returns a plot object. `plot!(plt,...)` modifies the plot object `plt` and returns it. If `plt` is not specified, the last plot touched is used.

In Juno and Jupyter, a plot is shown when it’s the output of the cell/line that was just run. It’s just like with any return value, except instead of showing a textual representation, it’s graphical. Your code ended in a `for` loop, which has the value `nothing`, so nothing is shown or printed.  
To see the plot, you can do

```julia
using Plots
plt = plot()
for r = ...
    ...
    plot!(x, y) # or plot!(plt,x,y)
end
plt

```

The last line is to display the plot `plt`.

---

<div class="post-metadata">

### Author: ![jlperla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlperla/32/34332_2.png) [@jlperla](https://discourse.julialang.org/u/jlperla)
#### Post date: [February 5, 2019, 5:28pm UTC](https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479/3 "2019-02-05T17:28:39Z")

</div>

Are you doing this in Jupyter or a `.jl` file? It can matter when `for` loops are involved… my suggestion is to stay in Jupyter for this sort of stuff unless your loops in a function.

---

<div class="post-metadata">

### Author: ![tomf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomf/32/6995_2.png) [@tomf](https://discourse.julialang.org/u/tomf)
#### Post date: [February 6, 2019, 2:52am UTC](https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479/4 "2019-02-06T02:52:01Z")

</div>

I was doing this directly in Jupyter.

---

<div class="post-metadata">

### Author: ![tomf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomf/32/6995_2.png) [@tomf](https://discourse.julialang.org/u/tomf)
#### Post date: [February 6, 2019, 3:17am UTC](https://discourse.julialang.org/t/understanding-basic-plots-behavior/20479/5 "2019-02-06T03:17:30Z")

</div>

Thanks! That’s it exactly.

(In a Python notebook the plotting is a side effect, and the value doesn’t matter. Hence my confusion.)
