Bar plot with lower values not fixed
1 回表示 (過去 30 日間)
古いコメントを表示
I'd like to make a plot for 9 item, each having 2 bars spaced close together, showing two related values. I want to have the bottoms of each bar not fixed at 0 or at some fixed offset. i want to show the range of values for each object in other words, max and min. no outliers or whiskers or percentiles. Kind of like as shown in the picture, but with EACH of the bottoms of the bars specifiable in Y value, not fixed..
0 件のコメント
採用された回答
Star Strider
2023 年 9 月 25 日
x = (1 : 9).'; % Assume Column Vectors
xd = repmat([-0.1 0.1], numel(x), 1) + x
xos = 0.125; % Spatial Separation ('x')
y = rand(numel(x),2) % Y-Values
VarNames = ["A","B","C","D","E","F","G","H","I"];
figure
hold on
for k = 1:numel(x)
patch([xd(k,:) flip(xd(k,:))]-xos, [-1 -1 1 1]*y(k,1)/2, 'r')
patch([xd(k,:) flip(xd(k,:))]+xos, [-1 -1 1 1]*y(k,2)/2, 'b')
end
hold off
xticks(x)
xticklabels(VarNames)
This sets the bars to be symmetric about the midpoiint. It should not be difficult to adjust the code to use other options, since that simply requires changing the y-argument to the patch calls.
.
4 件のコメント
その他の回答 (1 件)
Sulaymon Eshkabilov
2023 年 9 月 25 日
This exercise can be done using bar(), xticks, xticklabels, xtickangle commands:
G = randi([0, 15], 9,2);
Names = {'A(x)'; 'AB(y)'; 'ABC(y)'; 'ABCD(x1)'; 'ABBA(y1)'; 'BAC(z1)'; 'DABA(x,y)'; 'DABC1(w)'; 'ABCD13(u)'};
bar(G), grid on
xticks(1:9)
xticklabels(Names)
xtickangle(45)
ylim([0, 16])
legend('ver: One', 'ver: Two')
参考
カテゴリ
Help Center および File Exchange で Bar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!