How to use boxes to plot a freqency band?
2 次查看(过去 30 天)
显示 更早的评论
I'd like to create a plot that looks similar to this:
Row1:| [_____] [_______] [_] [___] [___________]
Row2:| [________] [_] [______] [_________]
|____________________________________________________
Frequency
The idea is that Row1 and Row2 contain frequency spans that I would like to identify with boxes.
I can't seem to make the horizontal bar graph do something like this.
Any help is greatly apprecited. Thanks all!
0 个评论
回答(2 个)
Rick Rosson
2011-8-30
You may want to consider using patch objects. For more information:
>> doc patch
HTH.
Rick
0 个评论
Oleg Komarov
2011-8-31
% I suppose you have the starting and ending point of each block. % You have to ensure that they are monotonically increasing across rows and the number of columns is even.
sten = [1 3 7 14 16 17;
2 4 8 9 11 19];
% Create X coordinates for the boxes
clear X
szSt = size(sten);
df = diff(sten,[],2);
X(:,1:2:szSt(2)*2) = [sten(:,1) df];
X = [cumsum(X,2) sten(:,end)];
% Create the Y coordinates for the boxes
Y = repmat(bsxfun(@minus,[2.5; 1.5; 1.5; 2.5],0:szSt(1)-1), szSt(2)/2,1);
% Reshape
X = reshape(X.',4,[]);
Y = reshape(Y,4,[]);
% Figure and axes
figure('units','pix','pos',[300 200 640 140])
axes('units','pix','pos',[20 20 600 100],'Xlim',[0 max(sten(:))+1],...
'Ylim',[0 szSt(1)+.5],'Ytick',1:szSt(1),'YtickL',szSt(1):-1:1)
patch(X,Y,ones(size(X)))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!