# Plotting error ("hold all-plots")

**URL:** https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580
**Category:** General Usage
**Tags:** plotting
**Created:** [January 13, 2019, 1:38am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580 "2019-01-13T01:38:52Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [January 13, 2019, 1:38am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/1 "2019-01-13T01:38:52Z")

</div>

Dear All,

now I am plotting some figures (simple) usig Julia, but It seems not working, i think “hold on” could be the reason??

function Bernstein(n,i,t)

Brnbasis=factorial(BigInt(n))/factorial(BigInt(i))/factorial(BigInt(n-i)) _(1/2+t/2)^i_(1/2-t/2)^(n-i)  
return(Brnbasis)  
end

using PyPlot  
#using Plots  
#pyplot()

n=2 # 2nd/4th order of polynomial  
dt=1/50  
t=-1:dt:1  
y=zeros(size(t))  
for i=0:n  
for dt=1:size(t,2)  
y(dt)=Bernstein(n,i,t(dt))  
end  
plot(t,y, reuse=false)  
end  
#xlabel(“X’); ylabel('Y”)

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [January 13, 2019, 5:37am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/2 "2019-01-13T05:37:35Z")

</div>

The `y(dt) = ...` is function declaration syntax in julia, instead use `y[dt] = ...`. I am not familiar with `PyPlot` but usually if you want `hold on` MATLAB behaviour , you can use `plot!(...)` for later plots after first plot in julia plot libraries.

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [January 13, 2019, 6:41am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/3 "2019-01-13T06:41:16Z")

</div>

Thanks!

I have changed the codes (plot!) as the following:

function Bernstein(n,i,t)

Brnbasis=factorial(BigInt(n))/factorial(BigInt(i))/factorial(BigInt(n-i)) _(1/2+t/2)^i_ (1/2-t/2)^(n-i)  
return(Brnbasis)  
end

#using PyPlot  
using Plots  
pyplot()

n=2 # 2nd/4th order of polynomial  
dt=1/50  
t=-1:dt:1  
y=zeros(size(t))  
for i=0:n  
for dt=1:size(t,1)  
y[dt]=Bernstein(n,i,t[dt])  
end  
plot!(t,y)  
end  
#xlabel(“X’); ylabel('Y”)

But it shows no result…

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [January 13, 2019, 7:41am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/4 "2019-01-13T07:41:55Z")

</div>

A for loop does not return a result.  
Add plot!() at the end to see the plot.

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [January 13, 2019, 8:05am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/5 "2019-01-13T08:05:48Z")

</div>

it shows me one curve in Julia, the correct results are three curves in MATLAB.

In MATLAB is  
plot(t,y,‘LineWidth’,2);  
hold all;

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [January 13, 2019, 8:06am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/6 "2019-01-13T08:06:55Z")

</div>

In addition, why size(t,1) in Julia is equal to :size(t,2) in MATLAB??

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [January 13, 2019, 11:26am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/7 "2019-01-13T11:26:00Z")

</div>

Because Julia is column-major.

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [January 13, 2019, 11:28am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/8 "2019-01-13T11:28:35Z")

</div>

Okay, If I use two times “plot!()”, it shows me correct results, thanks!

---

<div class="post-metadata">

### Author: ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)
#### Post date: [January 13, 2019, 11:31am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/9 "2019-01-13T11:31:11Z")

</div>

In Julia, PyPlot will `hold on` automatically. Just use the correct syntax for indexing and function call.

```julia
function Bernstein(n,i,t)
    Brnbasis=factorial(BigInt(n))/factorial(BigInt(i))/factorial(BigInt(n-i)) #(1/2+t/2)^i(1/2-t/2)^(n-i)
    return(Brnbasis)
end

using PyPlot

n = 2 # 2nd/4th order of polynomial
dt = 1/50
t = -1:dt:1
y = zeros(size(t))
for i = 0:n
    for dt = 1:size(t,2)
        y[dt] = Bernstein(n,i,t[dt])
    end
    plot(t,y)
end
xlabel("X"); ylabel("Y")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/4/e48d716db8b81638faf756351ba6da1afd76040c.png)

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [January 13, 2019, 11:38am UTC](https://discourse.julialang.org/t/plotting-error-hold-all-plots/19580/10 "2019-01-13T11:38:30Z")

</div>

this method also works, thanks!
