我正在使用imagesc
和一个共同colorbar
在matlab 3014b中绘制多个热图。这是我的代码:
a(1)= subplot('Position',[0.1, 0.65, 0.3, 0.3]);
data1 = rand(5);
imagesc(data1)
ax = gca;
ax.XTick = [1 2 3 4 5 6];
ax.XTickLabel = {'0','0.1', '0.2', '0.3','0.4','0.5'};
ax.YTick = [1 2 3 4 5 6];
ax.YTickLabel = {'1','10', '100', '1000', '10000', '100000'};
a(2)= subplot('Position',[0.45, 0.65, 0.3, 0.3]);
data2 = rand(5);
imagesc(data2)
ax = gca;
ax.XTick = [1 2 3 4 5 6];
ax.XTickLabel = {'0','0.1', '0.2', '0.3','0.4','0.5'};
ax.YTick = [1 2 3 4 5 6];
ax.YTickLabel = {'1','10', '100', '1000', '10000', '100000'};
h=colorbar;
set(h, 'Position', [.8 .135 .0581 .8150])
for i=1:2
pos=get(a(i), 'Position');
set(a(i), 'Position', [pos(1) pos(2)]);
end
但是我收到以下错误:
Error using matlab.graphics.axis.Axes/set
While setting the 'Position' property of Axes:
Value must be a 4 element vector
不完全确定如何解决此问题?谢谢!
答案 0 :(得分:1)
错误就在这里:
for i=1:2
pos=get(a(i), 'Position');
set(a(i), 'Position', [pos(1) pos(2)]); %// <--- here
end
你是否有截断最后两个元素的特殊原因? Position
应该是一个4元素向量,其中前两个元素定义从容器的左下角到轴的左下角的距离,第三个和第四个元素是宽度和高度窗口内的轴。如果您打算将所有轴保持相同的宽度/高度,请执行以下操作:
for i=1:2
pos=get(a(i), 'Position');
set(a(i), 'Position', [pos(1) pos(2) 1 1]); %// Change
end
在轴属性上查看有关MathWorks的文档...具体Position
此处:http://www.mathworks.com/help/matlab/ref/axes-properties.html#zmw57dd0e52524