-
Notifications
You must be signed in to change notification settings - Fork 3
/
PlotAxisAtOrigin.m
54 lines (45 loc) · 1003 Bytes
/
PlotAxisAtOrigin.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
function PlotAxisAtOrigin(x,y);
%PlotAxisAtOrigin Plot 2D axes through the origin
% This is a 2D version of Plot3AxisAtOrigin written by Michael Robbins
% File exchange ID: 3245.
%
% Have hun!
%
% Example:
% x = -2*pi:pi/10:2*pi;
% y = sin(x);
% PlotAxisAtOrigin(x,y)
%
% PLOT
if nargin == 2
plot(x,y);
hold on;
else
display(' Not 2D Data set !')
end;
% GET TICKS
X=get(gca,'Xtick');
Y=get(gca,'Ytick');
% GET LABELS
XL=get(gca,'XtickLabel');
YL=get(gca,'YtickLabel');
% GET OFFSETS
Xoff=diff(get(gca,'XLim'))./40;
Yoff=diff(get(gca,'YLim'))./40;
% DRAW AXIS LINEs
plot(get(gca,'XLim'),[0 0],'k');
plot([0 0],get(gca,'YLim'),'k');
% Plot new ticks
for i=1:length(X)
plot([X(i) X(i)],[0 Yoff],'-k');
end;
for i=1:length(Y)
plot([Xoff, 0],[Y(i) Y(i)],'-k');
end;
% ADD LABELS
text(X,zeros(size(X))-2.*Yoff,XL);
text(zeros(size(Y))-3.*Xoff,Y,YL);
box off;
% axis square;
axis off;
set(gcf,'color','w');