File Exchange

image thumbnail

mseb(x,y,errBar,lin​eProps,transparent)

version 1.3.0.0 (8.45 KB) by Andreas Trier Poulsen
Creates a 2D plot containing multiple lines with pretty shaded error bars.

34 Downloads

Updated 13 Feb 2015

View License

This is a tool for plotting multiple lines with pretty shaded error bars.
It is an extension of the popular shadedErrorBar, by Rob Campbell, enabling plotting of multiple data lines with overlapping errorbars.
The main improvements are:
* Optimised for the plot defult renderer instead of openGL, which is known to cause problems, e.g., with logarithmic axes and not being able to save figures as vector graphics in the eps-format.
* Turns off legends for all elements (e.g. edges and shaded area), except for the main lines.
* By default the edges of overshadowed patch areas are plotted in an non-obtrusive manner so all error bars can be seen, but avoids cluttering of the plot.
* The patches are plotted in reverse order to make sure the first entry is "on top".

Comments and Ratings (24)

menachom

Hey man,
This tool is great, but I am getting an invalid data argument when defining different linestyles while keeping the same color for all the lines:

lineProps.col{1} = 'k';
lineProps.col{2} = 'k';
lineProps.col{3} = 'k';
lineProps.col{4} = 'k';

lineProps.style{1} = ':';
lineProps.style{2} = '-';
lineProps.style{3} = '--';
lineProps.style{4} = '-.';

any ideas as to why?

Hi Giuseppe

I assume your critique is actually a question, and that you need help with figuring out how to specify the colours?

In the example you have given, you have two options to solve it:

1. lineProbs is optional, and as far as I remember the first default colour is blue, which is the colour you are trying to specify. So in your case, you can choose to just set lineProbs=[].

2. If you look in the documentation you can see that lineProps.col should be a cell array. Not just an array. You can also from the error see that it is being called as a cell array.
A general good advice is: If you can't figure out how some code works, then to check whether other people have had the same issues. In our case, on 12 May 2016 I have given an answer with examples on how to call mseb with specific colours.

I hope this helps you with the issues you are facing.

Cheers

figure();
lineProps.col=[0 0 1];
mseb(ta,A0,a0,lineProps,1)

>>Brace indexing is not supported for variables of this type.
>>Error in mseb (line 152)
>>H(c).mainLine=plot(x(c,:),y(c,:),'color',lineProps.col{c});

The description is poorly written.

Hi,
I'm starting to use this tool and but I have two small problems:
1/ is about the legend: I used latex interpreter but it doesn't work,
2/ I wonder if we have the possibility to change the colors of the lines.
Thank you in advance
Ilhem

Mario Solis

Rosalyn

mseb.m does not work when x and y are nx1 (column) vectors. The code converts the y data to a row vector, then complains that x and y do not have the same dimensions.

ezequiel

Hi, I would like to try the mseb, since I had problems to use the plots in adobe.

I work with 3 vectors 128x1 doubles.

- F 128x1 doubles, contains frequencies

- Im 128x1 doubles, contains coherency numbers

-Var 128x1 doubles, contains the variation of the coherencies.

For some reason, that I do not understand in line 94 the vector Im is changed => 94 y=y';

Thereafter it tells me that the vectors are not in the same size.

I order the inputs exactly as in the function shadederrorbars - which works well in matlab but has problems to exports, as you may know.

could someone clarify me this aspect?

Thanks

Hassan

Great work. Thanks!
When printing the output graphs as pdf and open it later with illustrator, I can't edit the file any more!
Any ideas...
Thanks

Adam Ranson

Hi Andreas, great work. For Inkscape users out there a similar procedure can be used to that described below to get transparent filled error bars:

- Create the graphs with solid error bars
- Save in .eps
- Open with Inkscape
- Select one triangle of the error bar
- Use Edit->Select Same->Fill and Stroke
- Select Object->Fill and Stroke and set Opacity to for example 50%.

I have a 2D vector which forms a loop and crosses over itself. Essentially a hysteresis loop. When I plot the error along this loop, the error regions overlap and voids result. Can this be prevented? I would like to see the overlapping areas as either a different color or a darker color (EX: Like two translucent areas overlapping).

Thanks!

Hi Andreas, thank for the explanation! That's a good way to solve the issue

(

I found a very easy way to overcome the raster rendering of the .eps export with the shaded error transparency and keep the vector. May be that's a Columbus egg but it can be useful:

- Create the graphs with solid error bars
- Save in .eps
- Open with Illustrator (for example)
- Select one triangle of the error bar
- Use the function 'Select', 'Same', 'Fill Color'
- Add the transparency on the selection

With few extra steps you'll have the mseb graphs with transparency in vector graphics

)

Cheers

Mario Solis

Mario Solis

Great, great work Andreas.
I would like to have a different lifestyle for each line (e.g. 'diamonds, squares, and a dotted lines'). Is it possible to do this without multiple calls for mseb?
Thanks!

Hi Alberto

Thank you for your feedback.

You can choose to plot using multiple calls to mseb (see example (2) below), but I created mseb to avoid this and be able to plot multiple lines in the same plot with one call.

Also, mseb plots the lines, shaded error bars and their borders in a specific order to ensure that all can be seen where they overlap. I you plot each line with a seperate call to mseb, it can't do this, and you risk lines being covered by the shaded bars from lines plotted afterwards.

This is especially important if you use the default renderer (important if you save as vector graphics, such as eps.).

Here are two examples plotting the same data with one or three calls to mseb:

% Matlab examples
% Generating three lines collected into one matrix:
x = 1:100; y = randn(1,100,30)*10;
t = (1:100) - 50; y(2,:,:) = repmat(t,[1,1,30]);
y(2,:,:) = y(2,:,:) + 0.06.*y(2,:,:).^2 + randn(1,100,30)*10;
y(3,:,:) = repmat(t,[1,1,30]);
y(3,:,:) = 60 - abs(y(3,:,:))+ randn(1,100,30)*10;

% (1) Plot all at once
lineProps.col{1} = 'b';
lineProps.col{2} = 'r';
lineProps.col{3} = [0 0.5 0];

figure; title('All at once'),
H = mseb(x,mean(y,3), std(y,[],3), lineProps);

% (2) Plot using three calls to mseb
lineProps1.col{1} = 'b';
lineProps2.col{1} = 'r';
lineProps3.col{1} = [0 0.5 0];

figure; title('One at a time using hold on')
hold on
H1 = mseb(x,mean(y(1,:,:),3), std(y(1,:,:),[],3), lineProps1);
H2 = mseb(x,mean(y(2,:,:),3), std(y(2,:,:),[],3), lineProps2);
H3 = mseb(x,mean(y(3,:,:),3), std(y(3,:,:),[],3), lineProps3);

Just a clarification regarding the lineProps.col: if I add the 3 cells as in you example

lineProps.col{1} = 'b';
lineProps.col{2} = 'r';
lineProps.col{3} = [0 0.5 0];

how can I recall specific color/cell in single function?

For ex.

H1 = mseb(x,y1,errBar1,lineProps.col{1,1},transparent)
H2 = mseb(x,y2,errBar2,lineProps.col{1,2},transparent)
H3 = mseb(x,y3,errBar3,lineProps.col{1,3},transparent)

so that
- function H1 plots x,y1 in blue
- function H2 plots x,y2 in red
- function H3 plots x,y1 in [0 0.5 0]

Ana

Guzman

Perfect. Works simply and as advertised.

Hi Lyndon

Thank you for your feedback.

I have made some small change so you should be to define the colours using RGB values. You should even be able to mix the types as:
lineProps.col{1} = 'b';
lineProps.col{2} = 'r';
lineProps.col{3} = [0 0.5 0];

I hope this works.

Thanks this is perfect for what I need! Would you be able to add the ability to specify RGB color values? i.e. instead of lineprop.col={'g'} which is too bright of a green for my taste, i'd like to use lineprop.col={[0 0.5 0]}.

Hi Dominik

Thank you for providing feedback. I apologise for the late answer, but I seem to have forgot to put the file on my watch list.

The examples work when I run them on Matlab 2014a. Can you please tell me which version you are running?

I think I have had similar problems when calling the repmat function on older versions of matlab. I have therefore changed the way it is called, in hopes that this is the cause of your problems.

The new version have been updated. Can I get you to download it and see if it helped?

Sincerely

Andreas

Following up on my first post: The repmat error comes from line 120 of your script.

I am simply trying to plot several time series + their std devs; they are stored in 2 matrices with the same dimensions (n x m). So I have a matrix m1 with mean values m for n time steps. I also have a matrix m2 with a std deviation per mean value along each time step.

mseb([],m1,m2)

yields said repmat error. Using the shadedErrorBar function on each time series alone does work properly. for example:

shadedErrorBar([],m1(:,1),m2(:,1));

Any ideas what I am doing wrong here with your function? I'd love to be able to use it properly!

Thanks, this is exactly what I am looking for! Sadly I do have a little problem: everytime I try to use your function i get the following error:

Error using repmat
Too many input arguments.

I also get this error when I simply copy&paste your example! Can you maybe check your example?

Updates

1.3.0.0

Slight changes made to calls to "plot" so colours can be defined by using both strings and RGB vectors.
Also updated file description on this page.

1.2.0.0

Updated calls to the repmat function from using the repmat(A,P1,P2,...,Pn) format, to using repmat(A,[P1,P2,...,Pn]). This was done in hopes of supporting older versions of Matlab.

1.1.0.0

Changed screenshot.

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: raacampbell/shadedErrorBar

Inspired: errorshade, anomaly