如何为同一图中的不同子图设置公共y轴标签

时间:2017-11-07 09:23:02

标签: matlab plot matlab-figure

我试图在一个图中绘制三个不同的子图,到目前为止,我只能为它们中的每一个设置一个ylabel,这是没有意义的,因为每个子轴的y轴描绘的值subplot是指相同的变量(频率,单位为Hz)。

我想知道的是如何让它们共享同一个y轴标签

这里有代码,所以你可以看一下我到目前为止所做的事情:

% I defined the variables for the subplots
freq = 2; 
freq2 = 7;
freq3 = 30; % frequency in Hz
time = -1:.001:1; % -1 to 1 seconds in millisecond steps

% Formula for the plots (sinewave formula)
sinewave = 1*sin(2*pi*freq*time + 0);
sinewave2 = 1*sin(2*pi*freq2*time + 0);
sinewave3 = 1*sin(2*pi*freq3*time + 0);

% Different subplots
figure(1), clf
subplot(311);
plot(time,sinewave);

subplot(312);
plot(time,sinewave2);
set(gca,'xlim',[-1.1 1.1],'ylim',[-1.1 1.1]);
hold on;

subplot(313);
plot(time,sinewave3);
set(gca,'xlim',[-1.1 1.1],'ylim',[-1.1 1.1]); 
hold on;

% Now the labels (Which I want to change to show as common for the
% y-axis of the three subplots together)
xlabel('Time (ms)')
ylabel ('Frequency (Hz)')

0 个答案:

没有答案