how to change width and space in barplot?
18 次查看(过去 30 天)
显示 更早的评论
Dear all,
can someone tell me if its possible to change the width of the bars in a barplot (so that they are wider) and obtain some space between the bars (so that I have the same but bigger space across all bars) while keeping the position of the xticks fixed relative to the bars? For example, I have the xticks = 0,5,10,15... so that the 6th bar is exactly at xtick 5, the 11th bar at xtick 10 and so on. I'm trying to keep this while increasing the barwidth and barspacing. But maybe barwidth and barspacing are not optimal for this exercise? Can anyone tell me what I can do?
Thank you very much for your help!
2 个评论
Voss
2024-4-30
Can you post some runnable code that produces a bar plot like what you have now? Is it something like this?
N = 16;
data = rand(1,N);
bar(0:N-1,data)
xticks(0:5:N)
It's a little difficult to understand how the bar width and the space between the bars would both increase, unless you mean to increase the space taken up by the entire plot (i.e., increase the axes width).
回答(1 个)
Voss
2024-4-30
"increase the width of the axis so that it is less compressed"
Well, you can resize the figure, either manually or programmatically. By default, the axes will be resized automatically when the figure changes size.
Here's an example of creating a wide figure programmatically:
Z=rand(26, 1);
t=0:1:25;
figure('Position',[10 10 1000 300]) % make a wide figure
hold on
grid on
bar(t,Z(1:t(end)+1,1),'FaceColor','r','LineWidth',10,'EdgeColor','none');
xlabel('Quarters','FontSize',12,'interpreter','latex');
ylabel('Percent','FontSize',12,'interpreter','latex');
hold on
xmax=t(end);
xstep=5;
xlim([0 xmax]);
xticks(0:xstep:xmax);
Is that on the right track?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!