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:
You must wait 2 days from the time you originally asked your question before you can accept your own answer. This gives other users a chance to answer the question in good faith, and earn the accepted answer.
The shortest option you have is https://stackoverflow.com/u/YOUR_USER_ID .
To post a job to StackOverflow you'll need to sign up for an account with careers.stackoverflow.com. Select 'log in' in the top right corner of the homepage, and then 'create a new account' from the page that follows. Just enter your email address and a password to complete your sign up.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With