Reputation: 222591
Here is the problem I am facing. I have the code, which builds some bar plots.
In order to compare them better, I need all them have the same scale. Looking at doc bar, I was not able to find how to specify that a bar plot has a specific maximum height.
So in my case, for example I have the following code:
c = [0 0 12 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
e = [0 2 5 6 5 2 0 0 0 0 0 0 0 0 0 0 0 0 0];
f = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19];
b = [0 9 7 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0];
subplot(2,2,1)
bar(b)
subplot(2,2,2)
bar(e)
subplot(2,2,3)
bar(f)
subplot(2,2,4)
bar(c)
The first subplot has height of 10, than 6, than 20 than 15.
Is there an easy way to have all of them their maximum height as 20.
Upvotes: 3
Views: 9862
Reputation: 9317
You can use the linkaxes
command:
h(1) = subplot(2,2,1)
bar(b)
h(2) = subplot(2,2,2)
bar(e)
h(3) = subplot(2,2,3)
bar(f)
h(4) = subplot(2,2,4)
bar(c)
linkaxes(h)
ylim([0 20])
Upvotes: 7
Reputation: 74940
You can easily change axes properties using the set
command and the handles (=identifiers) of the axes. If you haven't stored the axes handles (first output of subplot
), you first have to find them:
%# collect axes handles
axH = findall(gcf,'type','axes');
%# set the y-limits of all axes (see axes properties for
%# more customization possibilities)
set(axH,'ylim',[0 20])
Upvotes: 5