2013-06-11 174 views
8

我要绘制这样的事情:如何在MATLAB图上获取坐标轴上的箭头?

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)); 

我不能设法得到类似此图中那些轴:

enter image description here

我知道我可以去掉顶部和像this question中的右行,但我不知道如何获得边缘上的箭头。

我不需要额外的注释,但我想删除坐标轴上的刻度。我知道如何做到这一点,当轴是“正常”,但我不知道当轴已经被操纵时是否必须以另一种方式完成。

有谁知道如何做到这一点?

+4

只是一个警告:MATLAB是不是这类工作的合适的工具。这种数字是(也应该是)数量级的事情,对于这种数据,Inkscape,MS油漆,GIMP或类似的应该足够了。尽管在MATLAB中可以做到这一点,但要准备好看到一些很长很丑的代码,除了尝试以外,还会减少MATLAB默认使用的更详细的绘图方法的细节。 –

回答

12

好了,不要说我没提醒你:)

% 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) 

结果:

enter image description here

+2

一个很大的+1,只是在我的脸上露出一个微笑:P我留下了深刻的印象(虽然没有感到惊讶,看到了你的xkcd图)。谢谢! –

5

符号数学工具箱有provisions for making these arrows,但没有那个工具箱,你被困在自己绘制箭头的位置。下面的代码应该是用于此目的的:

% determine position of the axes 
axp = get(gca,'Position'); 

% determine startpoint and endpoint for the arrows 
xs=axp(1); 
xe=axp(1)+axp(3)+0.04; 
ys=axp(2); 
ye=axp(2)+axp(4)+0.05; 

% make the arrows 
annotation('arrow', [xs xe],[ys ys]); 
annotation('arrow', [xs xs],[ys ye]); 

% remove old box and axes 
box off 
set(gca,'YTick',[]) 
set(gca,'XTick',[]) 
set(gca,'YColor',get(gca,'Color')) 
set(gca,'XColor',get(gca,'Color')) 

唯一的缺点是,对于一些身材窗口尺寸,你将有箭头下方的1个像素的白色边框,和轴的线宽属性设置为荒谬的小价值并没有帮助。

但是对于打印而言,小的白色边框应该没有关系。

+0

+1,像魅力一样工作!谢谢马丁! =) –

相关问题