Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get arrows on axes in MATLAB plot?

Tags:

plot

matlab

I want to plot something like this:

x = 0:0.01:10;
f = @(x) 50* 1.6.^(-x-5);
g = @(x) 50* 1.6.^(+x-10);
plot(x, f(x));
hold on
plot(x, g(x));

I can't manage to get axes similar to the ones in this figure:

enter image description here

I know I can remove the top and right lines like in this question, but I don't know how to get the arrows on the edges.

I don't need the additional annotations, but I would like to remove the ticks on the axes. I know how to do this when the axes are "normal", but I'm not sure if it must be done in another way when the axes are already manipulated.

Does anyone know how to do this?

like image 438
Stewie Griffin Avatar asked Jun 11 '13 15:06

Stewie Griffin


1 Answers

Well, don't say I didn't warn you :)

% Some bogus functions
f = @(x) 50* 1.6.^(-x-5);
g = @(x) 50* 1.6.^(+x-10);

% Point where they meet
xE = 2.5;
yE = f(xE);

% Plot the bogus functions
figure(1), clf, hold on
x = 0:0.2:5;
plot(x,f(x),'r',  x,g(x),'b', 'linewidth', 2)

% get rid of standard axes decorations
set(gca, 'Xtick', [], 'Ytick', [], 'box', 'off')

% Fix the axes sizes
axis([0 5 0 5])

% the equilibrium point
plot(xE, yE, 'k.', 'markersize', 20)

% the dashed lines
line([xE 0; xE xE], [0 yE; yE yE], 'linestyle', '--', 'color', 'k')

% the arrows
xO = 0.2;  
yO = 0.1;
patch(...
    [5-xO -yO; 5-xO +yO; 5.0 0.0], ...
    [yO 5-xO; -yO 5-xO; 0 5], 'k', 'clipping', 'off')

% the squishy wiggly line pointing to the "equilibrium" text
h = @(x)0.5*(x+0.2) + 0.1*sin((x+0.2)*14);
x = 2.7:0.01:3.5;
plot(x, h(x), 'k', 'linewidth', 2)

% the static texts
text(xE-yO, -0.2, 'Q^*', 'fontweight', 'bold')
text(-2*yO,   yE, 'P^*', 'fontweight', 'bold')
text(-2*yO,    4, 'Price', 'rotation', 90, 'fontsize', 14)
text(    4, -0.2, 'Quantity', 'fontsize', 14)
text(   .5,  4.2, 'Demand', 'fontsize', 14, 'rotation', -55)
text(   4.0,  3.3, 'Supply', 'fontsize', 14, 'rotation', +55)
text(   3.6,  2.1, 'Equilibrium', 'fontsize', 14)

Result:

enter image description here

like image 119
Rody Oldenhuis Avatar answered Sep 28 '22 03:09

Rody Oldenhuis