2013-06-11 172 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,像魅力一樣工作!謝謝馬丁! =) –

相關問題