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.

采纳的回答

dpb
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--

更多回答(1 个)

Totanly
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]);
I think this will solve your purpose.

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by