Plotting a figure with bars in stack

1 Ansicht (letzte 30 Tage)
Tanu Raghav
Tanu Raghav am 2 Aug. 2020
Bearbeitet: Totanly am 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.

Akzeptierte Antwort

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

Weitere Antworten (1)

Totanly
Totanly am 2 Aug. 2020
Bearbeitet: Totanly am 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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by