在matlab中设置位置会导致意外位置

时间:2015-08-26 13:36:36

标签: matlab subplot

我有以下matlab代码片段,它会相互产生两个子图。

h = figure;
sp1 = subplot(1,2,1); hold on;
plot(xenDates, yXenDates, '.', 'color', cmap(1,:));
plot(xenPatchDates, yXenPatchDates, '.', 'color', cmap(2,:));
xlabel('Time in Months');
ylabel('Cumulative Number');
legend('Vulnerabilities','Patches','Location','northoutside');
sp1Pos = get(sp1, 'Position');
sp2 = subplot(1,2,2); hold on;
sp2Pos = get(sp2, 'Position');
plot(kvmDates, yKvmDates, '.', 'color', cmap(1,:), 'Markersize', 10);
plot(kvmPatchDates, yKvmPatchDates, '.', 'color', cmap(2,:));
xlabel('Time in Months');
ylabel('Cumulative Number');
set(sp2, 'Position', [sp2Pos(1) sp1Pos(2) sp2Pos(3) sp1Pos(4)]);

由于图例位于第一个子图的顶部,我想手动调整第二个子图的大小,以便两者具有相同的大小。所以我得到位置值并在最后一行为subplot2设置它们。然而,奇怪的是,子图向下移动了一点,以使x轴不对齐。

当我打电话

时也会发生这种情况
pos = get(sp2, 'Position');
set(sp2, pos(1) pos(2) pos(3) pos(4));

直接接连。

我做错了什么或这是一个已知的问题?

更新

既不添加drawow;也不会将单位更改为像素。附上一张显示问题的图片。

Misaligned x axis

0 个答案:

没有答案