-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathM2S_plotaxes.m
71 lines (60 loc) · 1.67 KB
/
M2S_plotaxes.m
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
%% Function to plot lines on x=0 and y=0 to make it more visible
% Uses:
% M2S_plotaxes() - plots at [0,0]
% M2S_plotaxes('r') - plots red line at [0,0]
% M2S_plotaxes(':r') - plots red dotted line at [0,0]
% M2S_plotaxes('k',[1,3]) - plots black line at [1,3]
% M2S_plotaxes('-k',[50,NaN]) - plots black vertical line at x=50 only
% M2S_plotaxes('-k',[NaN,50]) - - plots black horizontal line at y=50 only
% NOTE: xy_vals contains the values that a vertical line should cross X and
% a horizontal line should cross Y
function M2S_plotaxes(line_color,xy_vals)
x_lim = xlim;
y_lim = ylim;
gca;
hold on
if nargin == 0
line_color = 'k';
x_vals = [0,0]';
y_vals = [0,0]';
xy_vals = [0,0]
elseif nargin == 1
x_vals = [0,0]';
y_vals = [0,0]';
xy_vals = [0,0]
elseif nargin == 2
x_vals = [xy_vals(1),xy_vals(1)]';
y_vals = [xy_vals(2),xy_vals(2)]';
% if the xy_vals given are lower or higher than the current plot limits
if xy_vals(1) < x_lim(1)
x_lim(1) = xy_vals(1);
end
if xy_vals(1) > x_lim(2)
x_lim(2) = xy_vals(1);
end
if xy_vals(2) < y_lim(1)
y_lim(1) = xy_vals(2);
end
if xy_vals(2) > y_lim(2)
y_lim(2) = xy_vals(2);
end
elseif nargin > 2
disp('Too many arguments for plotaxes function')
end
if nargin <= 2
% if prod(ylim) <= 0
% plot(x_vals,y_lim',line_color)
% end
plot(x_vals,y_lim',line_color)
% if prod(xlim) <=0
% plot(x_lim',y_vals,line_color)
% end
plot(x_lim',y_vals,line_color)
if isnan(xy_vals(1))
plot(xlim',y_vals,line_color)
end
if isnan(xy_vals(2))
plot(x_vals,ylim',line_color)
end
end
%axis tight