MATLAB Answers

Plotting a figure with bars in stack

조회 수: 1(최근 30일)
Tanu Raghav
Tanu Raghav 2 Aug 2020
편집: Totanly 2 Aug 2020
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.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2 Aug 2020
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--

  댓글 수: 0

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Totanly
Totanly 2 Aug 2020
편집: Totanly 2 Aug 2020
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]);
I think this will solve your purpose.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by