Skip to content

Instantly share code, notes, and snippets.

@Kappie Kappie/hline.m
Created Sep 30, 2016

Embed
What would you like to do?
The subscript of the label partially disappears into the line. I fixed that in the following way.
% Changed this:
if ~isempty(label)
yy=get(gca,'ylim');
yrange=yy(2)-yy(1);
yunit=(y-yy(1))/yrange;
magic_number = 0.02;
if yunit<0.2
text(x(1)+0.02*(x(2)-x(1)),y+0.02*yrange,label,'color',get(h,'color'))
else
text(x(1)+0.02*(x(2)-x(1)),y-0.02*yrange,label,'color',get(h,'color'))
end
end
% To this:
if ~isempty(label)
yy=get(gca,'ylim');
yrange=yy(2)-yy(1);
yunit=(y-yy(1))/yrange;
% Changed from 0.02 to 0.03
label_upper_margin = 0.03;
if yunit<0.2
text(x(1)+label_upper_margin*(x(2)-x(1)),y+label_upper_margin*yrange,label,'color',get(h,'color'))
else
text(x(1)+label_upper_margin*(x(2)-x(1)),y-label_upper_margin*yrange,label,'color',get(h,'color'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.