2014-10-12 428 views

回答

1

下面是使用文本註釋一點點的解決方法。基本上你清除當前XTICK標籤和類似的標籤替換它們,但您可以指定從軸的距離:

clc 
clear 
close all 

x = 1:20; 

hPlot = plot(x,sin(x)); 

set(gca,'xaxisLocation','top'); 

set(gca,'XTickLabel',[]); %// Clear current XTickLabel 

ylim = get(gca,'YLim'); %// Get y limit of the plot to place your text annotations. 

for k = 2:2:20 
    text(k,ylim(2)+0.1,num2str(k),'HorizontalAlignment','Center') %// Play with the 'ylim(1) -0.1' to place the label as you wish. 
end 

給予這樣的:

enter image description here

當然現在它的誇張和你如果需要,可以對y軸執行相同的操作(使用當前軸的'XLim'屬性,gca)。

+0

所以@Josef你試過我的建議嗎? – 2014-10-14 14:33:44

+0

嗨Benoit, sry,它花了我很長的時間來回答。你的解決方法對我來說工作得很好。我只是想知道是否有更直接的方法來做到這一點。無論如何,非常感謝你。 喬 – 2014-10-15 00:19:54

+0

確定沒問題!可能有某種方式與Java的東西,但我懷疑它是比這更直接:P無論如何很高興它的工作。 – 2014-10-15 02:56:44