# Plot arrow as upper limits in errorbar when I don't have lower bound

11 views (last 30 days)
Roberto Serafinelli on 22 Nov 2022
Hi,
I am dealing with a variable that is strictly positive, and for which the calculation sometimes give values of the errors that are larger than the value itself. For example "1+-3" cannot be reported like that but must be reported as "<4".
I also cannot plot them as regular errorbars. Sometimes in plots you see these type of data points as arrows pointing downwards, and I was asking if it is possible to do that in Matlab.
For example in the following code I want an arrow at point (56,11) pointing downwards. How do I do this?
y=[1 2 3 4];
x=[15 1 34 56]
ey=[0.1 0.2 0.3 7];
test1=find(ex>x);
y_upper=x(test1)+ex(test1);
x_upper=y(test1);
Kai on 22 Nov 2022
Edited: Kai on 22 Nov 2022
can you explain more about the first error? Do you mean you want "1 +- 3" to return only "<4" and ignore ">-2"? Also, your sample code doesn't have "ex" and "11" in the (56,11). For only showing downward arrows, MATLAB can be configured to only display negative or positive error range, you can check this link for details only show negtive range
Roberto Serafinelli on 22 Nov 2022
Hi Kai, thanks for the answer. Take the fourth point, 4+-7. Since the variable is strictly positive, it cannot take the values from -3 to 0. Therefore 4+-7 means that y can be anything below 4+7=11. So I want Matlab to put a data point at y=11 and draw an arrow pointing downwards (only half error bar won't do, I need an arrow). If there is no way to do this I will use scatter with triangles but arrows are my first option, if it's doable in Matlab.

Roberto Serafinelli on 23 Nov 2022
I solved this way, though it seems rather tortuous. I made a medley of both your advice, thank you very much for your help.
I hope is useful to other people googling the same thing:
x=[1 2 3 4 5 6]; % x variable
ex=[0.2 0.2 0.2 0.2 0.2 0.2]; %error on x
y=[2 3 4 7 6 12]; % variable that cannot be negative
ey=[1 1.6 2.4 9 4 14]; %error on y
% define some utility variables
x1=x;
ex1=ex;
y1=y;
ey1=ey;
i=find(ey>y); %search for all variables with upper limits
x1(i)=[]; %removes upper limits (this variable index 1 is for constrained values)
x2=x(i); %puts upper limits in this variable index 2
ex1(i)=[];
ex2=ex(i);
y1(i)=[];
y2=y(i);
ey1(i)=[];
ey2=ey(i);
y2max=y2+ey2; %This are the actual upper limits
kk=zeros(length(x2)); %as much zeroes as how many upper limits I have
figure('Position',[10 10 800 650])
hold on
e1=errorbar(x1,y1,ey1,ey1,ex1,ex1,'.','Color','black','MarkerSize',15); %plots constrained values with neg and pos errors
e2=errorbar(x2,y2max,kk,kk,ex2,ex2,'.','Color','black','MarkerSize',15); %plots upper limits as dots with x errors and no y errors
e3=errorbar(x2,y2,kk,ey2,kk,kk,'v','MarkerEdgeColor','black','MarkerFaceColor','black','Color','black','MarkerSize',6); %plots downwards triangles with only positive errors that connect to the dots of e2
set(gca,'Box','on')
axis([0 6.5 0 30])
set(gca,'Fontsize',18,'TickLabelInterpreter','latex')
xlabel(gca,'\$x\$','Fontsize',22,'interpreter','latex');
ylabel(gca,'\$y\$','Fontsize',22,'interpreter','latex');
hold off Jeffrey Clark on 23 Nov 2022
@Roberto Serafinelli, using the e = errorbar call where the inputs are given to draw individual lines (see and Multiple lines with error barsl) will return a list e of the lines it creates for the data. The e can be indexed individually and modified as shown in ErrorBar Properties - for the individule error cases (e.g., negative values) you could use the Downward-pointing triangle marker arrow head and modify the error line lengths/colors as needed.