Matlab:子批次的标题与上面的轴标签重叠

Matlab:子批次的标题与上面的轴标签重叠,matlab,plot,matlab-figure,axis-labels,subplot,Matlab,Plot,Matlab Figure,Axis Labels,Subplot,我有一个4x1图形图,其中一个图取上半部分。我在一个相对高分辨率的1600x1200显示器上观看,所以Matlab应该没有问题。考虑到我有一个4x2的数字,Matlabs适合所有东西,这尤其奇怪 那么4x1绘图有什么问题?我该如何解决它?为什么Matlab(2016b)不能像4x2一样为它做什么 identifier='unshielded'; bat_discharging=readtable('battery_discharging.txt','Format', '%u%f%f%f');

我有一个4x1图形图,其中一个图取上半部分。我在一个相对高分辨率的1600x1200显示器上观看,所以Matlab应该没有问题。考虑到我有一个4x2的数字,Matlabs适合所有东西,这尤其奇怪

那么4x1绘图有什么问题?我该如何解决它?为什么Matlab(2016b)不能像4x2一样为它做什么

identifier='unshielded';
bat_discharging=readtable('battery_discharging.txt','Format', '%u%f%f%f');

subplot(4,1,[1 2]);
yyaxis left;
plot(bat_discharging{:,1},bat_discharging{:,2});
ylabel('Voltage, V');
yyaxis right
plot(bat_discharging{:,1},bat_discharging{:,3});
hold on
plot(bat_discharging{:,1},bat_discharging{:,4});
ylabel('Current, A');
hold off
xlabel(bat_discharging.Properties.VariableNames{1});
legend('Voltage', 'Current with external reference',...
    'Current with internal refence', 'Location','east');
title( ['Discharging, ' identifier]);

subplot(4,1,3);
[ext_currentfit,ext_gof, ext_output] = fit(double(bat_discharging{:,1}),...
    bat_discharging{:,3}, 'smoothingspline');
plot(bat_discharging{10:end,1}, ext_output.residuals(10:end));
xlabel(bat_discharging.Properties.VariableNames{1});
ylabel('Current, A');
title(sprintf(...
    'Battery current measurement noise, external reference, %s, span=%.3e, %s=%e',...
    identifier,range(ext_output.residuals(10:end)),...
    '\sigma',std(ext_output.residuals(10:end))));

subplot(4,1,4);
[int_currentfit,ext_gof, int_output] = fit(double(bat_discharging{:,1}),...
    bat_discharging{:,4}, 'smoothingspline');
plot(bat_discharging{10:end,1}, int_output.residuals(10:end));
ylabel('Current, A');
xlabel(bat_discharging.Properties.VariableNames{1});
title(sprintf(...
    'Battery current measurement noise, internal reference, %s, span=%.3e, %s=%e',...
    identifier,range(int_output.residuals(10:end)),...
    '\sigma',std(int_output.residuals(10:end))));
“battery_discharging.txt”中的前20个数据集 应该足以让代码运行

    Sample  Voltage, V  Current external ref    Current internal ref
1   3.327263594e+00 -8.607864380e-05    -8.599996567e-05
2   3.326871395e+00 -8.591771126e-05    -8.585631847e-05
3   3.326753676e+00 -8.580327034e-05    -8.570969105e-05
4   3.326707184e+00 -8.567452431e-05    -8.563339710e-05
5   3.326638043e+00 -8.560776711e-05    -8.552610874e-05
6   3.326614201e+00 -8.551001549e-05    -8.547961712e-05
7   3.326560557e+00 -8.546590805e-05    -8.539199829e-05
8   3.326546252e+00 -8.538603783e-05    -8.535683155e-05
9   3.326498866e+00 -8.535146713e-05    -8.528172970e-05
10  3.326489627e+00 -8.528113365e-05    -8.525252342e-05
11  3.326448202e+00 -8.525490761e-05    -8.518755436e-05
12  3.326441050e+00 -8.518815041e-05    -8.516192436e-05
13  3.326403201e+00 -8.516669273e-05    -8.509933949e-05
14  3.326398730e+00 -8.510708809e-05    -8.508086205e-05
15  3.326362669e+00 -8.508801460e-05    -8.502542973e-05
16  3.326360881e+00 -8.503198624e-05    -8.500695229e-05
17  3.326325417e+00 -8.501410484e-05    -8.495271206e-05
18  3.326324224e+00 -8.496403694e-05    -8.493661880e-05
19  3.326291144e+00 -8.494853973e-05    -8.488714695e-05
20  3.326291144e+00 -8.489966393e-05    -8.487284184e-05

x = 1:100;
y = rand(100, 1);

subplot(3,1,[1 2]);
plot(x, y);
xlabel('label');

subplot(3,1,3);
plot(x, y);
title('TITLE');

我不知道是什么原因导致了这个问题,也无法重现它,但我认为最简单的解决方案是将手柄放在第一个轴上:

ax = subplot(4,1,[1 2]);
完成绘制后,将其向上移动一点:

ax.Position(2) = ax.Position(2)*1.02; % This may be adjusted
% subplot(4,1,3); etc...
这里我占2%,但你可能需要多一点。此外,通过同样的方式,您可以将最后一个轴稍微向下移动:

ax = subplot(4,1,4);
% do all the plotting
ax.Position(2) = ax.Position(2)*0.98; % This may be adjusted

创建一个@SardarUsama这个代码既简单又完整。并且有必要创建有问题的图形。我还包括了一些数据,需要放在一个名为“battery_discharging.txt”的文件中。你还错过了什么?什么是电池电压?当我在一个小得多的屏幕上运行你的脚本时(使用2017a),我看不出这个问题。@EBH这是一个复制粘贴错误,我最好在原始脚本中也修复它。非常感谢。也固定above@AndreyPro这段代码肯定不是您问题的最小表示。请看我在你的问题中添加的内容。所有其他特定于项目的信息都与您的真实问题无关,也会分散您的注意力,这会降低它对其他人的用处,请参阅