[英]Matlab, histogram plot data-value of bar
我想在Matlab的直方圖中顯示每個條的值。 我將所有圖保存為matlab .fig文件。 如何更改數字? 任何想法?
謝謝
它可能並不完美,但這是一個開始:
x =rand(10,1);
bar(x(:,1));
text(1:10,x,num2str(x))
更新:如果您想要直方圖而不是條形圖:
x =ceil(10*rand(30,1));
hist(x);
a = hist(x);
% This can most likely be done without a loop, but here goes:
for ii = 1:10
text(ii,a(ii),num2str(a(ii)))
end
您可以通過在a(ii)+0.1
或類似位置添加分配文本來抵消數字。 除此之外,請參閱Eitan的答案 ,以獲取一些提示和技巧。
這是一些代碼,用於從.fig
文件(帶有條形系列)中獲取Y
數據,然后顯示相應的文本。 Y
數據埋在當前axes
的子級中-我們需要兩次應用get
命令。
%create figure
h = figure('Color','w');
x =rand(10,1);
bar(x(:,1));
set(gca,'XLim', [0 11], 'YLim', [0 1]);
saveas(h,'myfig.fig');
close(h);
%open figure, get the bar data, then text
open('myfig.fig');
xdata = get(get(gca,'Children'), 'xData')
ydata = get(get(gca,'Children'), 'YData')
text(xdata, ydata, num2str(ydata',2), 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.