summaryrefslogtreecommitdiff
path: root/sharedfiles/scalemarker.m
blob: 88556cb165c0d5793d7089bb4f5f2d93e2f90496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% Puts a scale marker ("scale bar") on a plot at position (x,y).  The length of the
% marker is set by markerlength.  The string textlabel usually contains the
% "real life" length the marker is supposed to represent.  The final optional
% argument is the orientation.  It should be 'h' for horizontal (default) or 'v'
% for vertical.

function [h,th]=scalemarker(x,y,markerlength,textlabel,varargin);


if nargin>=5, orientation=varargin{1}; else orientation='h'; end

xlimits=get(gca,'XLim');
ylimits=get(gca,'YLim');
xrange=abs(diff(xlimits));
yrange=abs(diff(ylimits));

if orientation=='h'
    x1=x-markerlength/2;
    x2=x+markerlength/2;
    y1=y-yrange/90;
    y2=y+yrange/90;
    h=plot([x1 x2],[y y],'k-',[x1 x1],[y1 y2],'k-',[x2 x2],[y1 y2],'k-');
    th=text(x1,y2+yrange/75,[' ',textlabel]);
else
    x1=x-xrange/120;
    x2=x+xrange/120;
    y1=y-markerlength/2;
    y2=y+markerlength/2;
    h=plot([x x],[y1 y2],'k-',[x1 x2],[y1 y1],'k-',[x1 x2],[y2 y2],'k-');
    th=text(x2,y1,strvcat(textlabel,' ',' '));
end