![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340549/image.jpeg)
Plotting a figure with bars in stack
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I want to plot a figure in which I have two columns of number in increasing order and I want them to plotted like an image attached here. I have no idea how I can do this. The two columns of these bars are columns of number and each number is replaced by a bar.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340528/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340528/image.png)
댓글 수: 0
채택된 답변
dpb
2020년 8월 2일
Any number of ways; a braind-dead sample
y=sort(rand(20,2),1,'ascend'); % some dummy y data
figure,hold on % new figure, going to add more than one line
for x=0:2:2 % two sets of lines, specifically...
arrayfun(@(i)line([x x+1],[y(i,x/2+1) y(i,x/2+1)]),1:length(y)) % add the lines at y,arbitrary x
end
xlim([0 10]) % set the axis so lines are pleasing width
hAx=gca; hAx.Visible='off'; % don't want visible axis
hF=gcf; hF.Color='w'; % and white background
yields figure looking like--
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340549/image.jpeg)
댓글 수: 0
추가 답변 (1개)
Totanly
2020년 8월 2일
편집: Totanly
2020년 8월 2일
data=rand(50,50);
A=data(:,1);%your first column
B=data(:,2);%your second column
figure;xlim([1 2]);
for n1=1:length(A)
hold on
refline([0 A(n1)])
end
hold on
xlim([4 5]);
for n2=1:length(B)
hold on
refline([0 B(n2)])
end
xlim([0 6]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340552/image.png)
I think this will solve your purpose.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!