Can I change the width of a single bar in a bar plot?
26 次查看(过去 30 天)
显示 更早的评论
I have a grouped bar plot, bb:
bb = bar(x,y)
where x is a 7x1 double vector with month numbers and y is a 7x5 double vector with measurement data. For each of the seven time points, I get five bars with data.
I would like to add some spacing between the first two and the last three bars in each group. One idea I came up with is to add a column of NaNs to y (to make it 7x6 with the third column empty). However, this creates a very wide gap between my bars. I would prefer to make it smaller by changing the width of this 'NaN' bar in the plot while keeping the other bars as they are. Is there a way to do this?
0 个评论
回答(1 个)
Voss
2022-3-14
Does the gap still appear too wide if you widen the bars?
x = (1:7).';
y = rand(7,5);
new_y = NaN(size(y)+[0 1]);
new_y(:,[1 2 4:end]) = y;
% bb = bar(x,new_y);
bb = bar(x,new_y,'BarWidth',1);
3 个评论
Adam Danz
2022-3-14
There's no way to do that using the bar() command with grouped bars.
An ugly workaround may be possible such as plotting all bars individually and computing their x-coordinates but it sounds like a headache and something vulnerable to bugs.
Perhaps you could visually group them using color or xline lines but I haven't thought out the details.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!