2

I have some data and I am plotting the mean at each time point with error bars showing the standard deviation.

I can simply use errorbar(x, y, err) and this works fine for a single line. However, if I want to plot multiple data sets in the same plot, the error bars overlap and it looks bad:

error bars overlap and graph makes no sense

I would like the error bars to be side by side. So each regression is slightly displaced from the previous ones. Is there an easy way to do this that I am overlooking?

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
farid99
  • 712
  • 2
  • 7
  • 25
  • 3
    You could offset the `X` values passed to `errorbar` so they do not stack but this would shift the error bars off of your specific points in time. It would be helpful if you provided code that reproduces your issue. – sco1 Dec 01 '15 at 12:37
  • This is in the new graphics engine rigth? – Ander Biguri Dec 01 '15 at 15:27
  • If your X axis is categorical than @excaza solution is the most convenient one. Just use something like `s=[-1 1]; offx = x + rand(size(x)).*0.01.*x.*s(randi(2,size(x)))`. – EBH Jul 04 '16 at 19:00

1 Answers1

1

You can add a known or random offset to the x values of your points, e.g.

s=[-1 1]; 
offx = x + rand(size(x)).*0.01.*x.*s(randi(2,size(x)))
errorbar(offx, y, err)

Alternatively, R2018b introduced the stackedplot function. It's not what you were asking about (horizontal offset), but it might be useful (vertical offset, like subplot).

Dev-iL
  • 23,742
  • 7
  • 57
  • 99