spectrogram x-axis match with data
이전 댓글 표시
Hello, I am plotting a spectrogram from an earthquake signal, but the time length of the signal (~250 seconds) does not match the time length displayed in the spectrogram (~100 seconds). Could you help me understand why this discrepancy occurs and how to fix it? Thank you!

댓글 수: 2
Mathieu NOE
2025년 1월 22일
that is quite strange , but I cannot tell the reason as you don't show the code
to be sure to have same x axis display you can use xlim (with same values) on both subplots
Jorge Luis
2025년 1월 22일
채택된 답변
추가 답변 (1개)
this can also helps you :
%%Method 1: equate axis sizes for all axes after adding colorbar
% Size of axes without a colorbar will be set to the size of axes with a colorbar.
% Create Demo
ax = gobjects(2,3);
for i = 1:5
ax(i) = subplot(3,2,i);
imagesc(ax(i),rand(100,1000))
colorbar(ax(i))
end
ax(end) = subplot(3,2,6);
plot(ax(end), 1:1000,(1:1000).*rand(1,1000)*2)
% Set the width and height of all axes to the min width & height
allAxPos = vertcat(ax.Position);
allAxPos(:,3:4) = min(allAxPos(:,3:4)).*ones(numel(ax),1);
set(ax,{'position'},mat2cell(allAxPos,ones(numel(ax),1),4))
%%Method 2: Restore axis position and set colobar positions
% The axes maintain their original sizes prior to adding colorbar.
% The colorbar position and width is adjusted.
function addOutsideColorbar(ax)
pos = ax.Position;
cb = colorbar(ax,'EastOutside');
ax.Position = pos;
cb.Position(1) = sum(ax.Position([1,3]))+.01;
cb.Position(3) = cb.Position(3).*.5;
end
ax = gobjects(2,3);
for i = 1:5
ax(i) = subplot(3,2,i);
imagesc(ax(i),rand(100,1000))
addOutsideColorbar(ax(i))
end
ax(end) = subplot(3,2,6);
plot(ax(end), 1:1000,(1:1000).*rand(1,1000)*2)
%%Method 3: Use tiledlayout
ax = gobjects(2,3);
tlo = tiledlayout(3,2);
for i = 1:5
ax(i) = nexttile(tlo);
imagesc(ax(i),rand(100,1000))
colorbar(ax(i))
end
ax(end) = nexttile(tlo);
plot(ax(end), 1:1000,(1:1000).*rand(1,1000)*2)
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



