# Incorrect mean in the EnsembleSummary plot?

**URL:** https://discourse.julialang.org/t/incorrect-mean-in-the-ensemblesummary-plot/125325
**Category:** Numerics
**Tags:** question, plotting, diffeq, recipe
**Created:** [January 29, 2025, 12:10am UTC](https://discourse.julialang.org/t/incorrect-mean-in-the-ensemblesummary-plot/125325 "2025-01-29T00:10:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)
#### Post date: [January 29, 2025, 12:10am UTC](https://discourse.julialang.org/t/incorrect-mean-in-the-ensemblesummary-plot/125325/1 "2025-01-29T00:10:42Z")

</div>

I have the following snippet:

```julia
module mwe

using OrdinaryDiffEq
using Plots
using Distributions
using Statistics

tspan = (0.0, 10.0)
Δt = 0.5
g(u, p, t) = p[1] * t
x0 = 0.0

# base problem
prob_x = ODEProblem(g, x0, tspan, [1])

# ensemble problem
dist_a = Exponential()
function prob_func(prob, i, repeat)
    remake(prob, p=[rand(dist_a)])
end
n_traj = 10^4
ensemble_prob = EnsembleProblem(prob_x, prob_func=prob_func)
sim = solve(ensemble_prob, Euler(), dt=Δt, EnsembleThreads(), trajectories=n_traj)
display(plot(EnsembleSummary(sim)))

println("Mean at the final time")
display(mean([a[end] for a in sim.u]))

end # module mwe

```

which outputs

```julia
Mean at the final time
47.418223069301085

```

and

 ![ensemble](https://global.discourse-cdn.com/julialang/original/3X/8/2/824dc3bcde9c1f1cb5cb1b5bc3540c107b7a0204.png)

Do I understand it correctly that the thick blue line in the plot of the `EnsembleSummary` is the mean as a function of time? And `[a[end] for a in sim.u]` gets me the endpoint of every trajectory? If so, why the plot mean at `tspan[end]` is 30 and the calculated mean is 47? If not, where am I mistaken?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 29, 2025, 5:51pm UTC](https://discourse.julialang.org/t/incorrect-mean-in-the-ensemblesummary-plot/125325/3 "2025-01-29T17:51:48Z")

</div>

It is plotting the median, see [here](https://github.com/SciML/SciMLBase.jl/issues/132).

The default `ci_type=:quantile` uses the median.

To plot the mean do:

```julia
plot(EnsembleSummary(sim); ci_type=:SEM)

```
