Plotting a figure with bars in stack

1 回表示 (過去 30 日間)
Tanu Raghav
Tanu Raghav 2020 年 8 月 2 日
編集済み: Totanly 2020 年 8 月 2 日
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 Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by