How can I let my stack overflow?
Asked Answered
B

1

10

I want to make a bar chart in Matlab, where one of the categories is "breaking through the roof" of the axes, over the y-axis limit, but I can't figure how to do this. When I change the upper limit to a lower value, the bar gets trucked.

What can I do?

Here is my data:

data =
   115   116    97    99   107   NaN   NaN   NaN
   111   118   101   114   102   108   111   119

I want the upper y-axis limit to be 600.

Here is what I tried:

bar(data,0.5,'stack')
ylim([0 600])

Here is a demonstration of the result:

stack not overflow

Bolan answered 1/3, 2017 at 23:18 Comment(2)
It was a bit difficult to understand what you want to do, before seeing the answer...Clytemnestra
asking a stackoverlow question on stack overflow - you got to appreciate :DEolande
B
12

One simple option is to set the clipping property of the axes to off.

bar(data,'stack')
colormap('lines') % make it colorfull :)
bax = gca; % get axis handle
bax.Clipping = 'off';
bax.YLim(2) = 600; % set the upper limit

For a better result, you might want to also shrink the axes a little, so the bar will stay within the figure. Also, it's nicer without boxing the axes:

top = bax.YLim(2); % before you change the limit
bax.YLim(2) = 600; % set the upper limit
bax.Position(4) = bax.Position(4)*(bax.YLim(2)/top);
box off

the result:

stack overflow

Bolan answered 1/3, 2017 at 23:18 Comment(1)
Good to know! I don't remember having used that clipping property in the pastBred

© 2022 - 2024 — McMap. All rights reserved.