# Plots.jl error bar bar()

**URL:** https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908
**Category:** Visualization
**Created:** [July 17, 2017, 6:37pm UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908 "2017-07-17T18:37:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![iara\_iapc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iara_iapc/32/1084_2.png) [@iara\_iapc](https://discourse.julialang.org/u/iara_iapc)
#### Post date: [July 17, 2017, 6:37pm UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908/1 "2017-07-17T18:37:47Z")

</div>

Hello everyone

I have a little problem. How to put the yerr in the bar chart? The code below does not work ☹

```julia
using Plots
plotlyjs()

bar_plot = bar()

data = [(rand()+1) * randn(n) + i for i in 1:5]

for i = 1:5
    bar_plot = bar!([mean(data[i])], yerr = std(data[i]))
end

bar_plot

```

---

<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 17, 2017, 7:37pm UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908/2 "2017-07-17T19:37:34Z")

</div>

Maybe this is backend specific? I know Plotly can’t do ribbon plots.

---

<div class="post-metadata">

### Author: ![iara\_iapc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iara_iapc/32/1084_2.png) [@iara\_iapc](https://discourse.julialang.org/u/iara_iapc)
#### Post date: [July 17, 2017, 8:01pm UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908/3 "2017-07-17T20:01:32Z")

</div>

Hi Chris  
I tried with the GR and the result is the same.

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [July 18, 2017, 1:17am UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908/4 "2017-07-18T01:17:18Z")

</div>

You probably meant:

```julia
bar_plot = bar()

for i = 1:5
    bar!(bar_plot, [mean(data[i])], yerr = std(data[i]))
end

bar_plot

```

where the function `bar!` is modifying the plot in place (see the Plots.jl docs for this “in place” plotting).  
For some reason though, when adding more bar plots, the error bars don’t move and all stay in the middle of the plot (at least with `plotlyjs()`), I guess you could open an issue for that on Plots.jl repo.

It’s probably easier and more readable to do it in one command:

`bar(mean.(data), yerr = std.(data))`

As a minor OT: there is the `StatPlots.shadederror` function in StatPlots.jl that can do ribbon like plots (i.e. solid line with semitransparent ribbon around it) on all backends I’ve tested (including plotly).

---

<div class="post-metadata">

### Author: ![iara\_iapc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iara_iapc/32/1084_2.png) [@iara\_iapc](https://discourse.julialang.org/u/iara_iapc)
#### Post date: [July 18, 2017, 1:37am UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908/5 "2017-07-18T01:37:47Z")

</div>

Hi plever  
When I run the code, it occurs:

```julia
WARNING: Array{T}(::Type{T}, m::Int) is deprecated, use Array{T}(m) instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
 [2] Array(::Type{Float64}, ::Int64) at ./deprecated.jl:57
 [3] error_coords(::UnitRange{Int64}, ::Array{Float64,1}, ::Float64) at /home/jmarcellopereira/.julia/v0.6/Plots/src/recipes.jl:706
 [4] macro expansion at /home/jmarcellopereira/.julia/v0.6/Plots/src/recipes.jl:730 [inlined]
 [5] apply_recipe(::Dict{Symbol,Any}, ::Type{Val{:yerror}}, ::UnitRange{Int64}, ::Array{Float64,1}, ::Void) at /home/jmarcellopereira/.julia/v0.6/RecipesBase/src/RecipesBase.jl:259
 [6] _process_seriesrecipe(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}) at /home/jmarcellopereira/.julia/v0.6/Plots/src/pipeline.jl:404
 [7] _plot!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Float64,1}}) at /home/jmarcellopereira/.julia/v0.6/Plots/src/plot.jl:227
 [8] #plot!#141(::Array{Any,1}, ::Function, ::Plots.Plot{Plots.PlotlyJSBackend}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /home/jmarcellopereira/.julia/v0.6/Plots/src/plot.jl:151
 [9] (::Plots.#kw##plot!)(::Array{Any,1}, ::Plots.#plot!, ::Plots.Plot{Plots.PlotlyJSBackend}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at ./<missing>:0
 [10] #bar!#389(::Array{Any,1}, ::Function, ::Plots.Plot{Plots.PlotlyJSBackend}, ::Vararg{Any,N} where N) at /home/jmarcellopereira/.julia/v0.6/RecipesBase/src/RecipesBase.jl:355
 [11] (::Plots.#kw##bar!)(::Array{Any,1}, ::Plots.#bar!, ::Plots.Plot{Plots.PlotlyJSBackend}, ::Vararg{Any,N} where N) at ./<missing>:0
 [12] macro expansion at ./In[10]:4 [inlined]
 [13] anonymous at ./<missing>:?
 [14] include_string(::String, ::String) at ./loading.jl:515
 [15] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /home/jmarcellopereira/.julia/v0.6/IJulia/src/execute_request.jl:160
 [16] eventloop(::ZMQ.Socket) at /home/jmarcellopereira/.julia/v0.6/IJulia/src/eventloop.jl:8
 [17] (::IJulia.##11#14)() at ./task.jl:335
while loading In[10], in expression starting on line 3

```

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [July 18, 2017, 1:53am UTC](https://discourse.julialang.org/t/plots-jl-error-bar-bar/4908/6 "2017-07-18T01:53:42Z")

</div>

> [@iara\_iapc](#):
>
> [3] error\_coords(::UnitRange{Int64}, ::Array{Float64,1}, ::Float64) at /home/jmarcellopereira/.julia/v0.6/Plots/src/recipes.jl:706

It simply means that the Plots.jl package has not yet solved all the deprecation warnings relative to julia 0.6. It’s safe for you to ignore the warning I think.

As for your plot, as mentioned on gitter, you should maybe also specify the x coordinate, to be sure you know where the bars end up, i.e. :

```julia
for i = 1:5
    bar!(bar_plot, [i], [mean(data[i])], yerr = std(data[i]))
end

```
