# Plot with ribbon in MonteCarloMeasurements.jl

**URL:** <https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [August 5, 2022, 5:36pm UTC](https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360 "2022-08-05T17:36:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Firstname\_Lastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstname_lastname/32/34201_2.png) [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Post date:** [August 5, 2022, 5:36pm UTC](https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360/1 "2022-08-05T17:36:59Z")

</div>

Given a function `y = a * x + b` where `a` and `b` are of the type Particles. By using MonteCarloMeasurements.jl and Plots.jl, I can plot many sample function y(x) as follows

```julia
using MonteCarloMeasurements
using Plots

p = Particles(1000, MvNormal([0,0],[2. 1; 1 4]))
p2mat = Matrix(p)
f(x,a,b) = a*x + b
fig = plot(legend=false)
[plot!(x->f(x,p2mat[i,1],p2mat[i,2])) for i = 1:30]
fig

```

Please tell me how can I plot `y(x)` with ribbon with (0.05;0.95) quantile?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 6, 2022, 8:05am UTC](https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360/2 "2022-08-06T08:05:42Z")

</div>

If you plot vectors of particles instead of using the function interface to plot, you should get ribbons automatically.

---

<div class="post-metadata">

**Author:** ![Firstname\_Lastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstname_lastname/32/34201_2.png) [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Post date:** [August 7, 2022, 12:17am UTC](https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360/3 "2022-08-07T00:17:45Z")

</div>

Thank you @baggepinnen. Following your suggestion [if I understand correctly], I already tried

```julia
using MonteCarloMeasurements
using Plots
p = Particles(1000, MvNormal([0,0],[2. 1; 1 4]))
a = p[1]
b = p[2]
f(x) = a*x + b
plot(x->f(x))

```

It returns to the following error  
`ERROR: MethodError: no method matching Float64(::Particles{Float64, 1000})`

I also tried with

```julia
x = LinRange(1:0.1:3)
ribbonplot(x,f(x))

```

but still failed with error  
`ERROR: MethodError: no method matching +(::Vector{Particles{Float64, 1000}}, ::Particles{Float64, 1000})`

Could you please be more specific to show me your solution?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 7, 2022, 3:55am UTC](https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360/4 "2022-08-07T03:55:16Z")

</div>

> [@Firstname\_Lastname](#):
>
> ```julia
> x = LinRange(1:0.1:3)
> ribbonplot(x,f(x))
> 
> ```

You must broadcast the function `f` over `x` since `x` is a vector and `f` only works for scalar `x`.

Try this

```julia
x = LinRange(1:0.1:3)
plot(x,f.(x))

```

---

<div class="post-metadata">

**Author:** ![Firstname\_Lastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstname_lastname/32/34201_2.png) [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Post date:** [August 7, 2022, 9:24am UTC](https://discourse.julialang.org/t/plot-with-ribbon-in-montecarlomeasurements-jl/85360/5 "2022-08-07T09:24:18Z")

</div>

Great, thank you for your help.
