2013-03-25 71 views
3

这是我面临的问题。我有代码,它构建了一些条形图。如何确保子图上的所有Y轴具有相同的值

为了比较他们更好的,我需要他们有相同的规模。看着文档栏,我无法找到如何指定条形图具有特定的最大高度。

所以在我的情况下,例如我有以下代码:

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) 

第一副区有10的高度,比6,20比15。

有没有一种简单的方法将它们的最大高度设置为20.

回答

7

可以使用linkaxes命令:

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]) 
5

使用set命令和轴的手柄(=标识符)可以轻松更改轴属性。如果您还没有存储轴手柄(的subplot第一输出),你首先要找到他们:

%# 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]) 
+0

你怎么知道哪个坐标轴属于哪个情节?我似乎无法解决'findall'返回的排序问题 – Alex 2016-08-15 05:53:15

相关问题