필터 지우기
필터 지우기

Why is there an offset in my X axis in my subplots?

조회 수: 12 (최근 30일)
Larissa Perez
Larissa Perez 2018년 10월 30일
답변: Star Strider 2018년 10월 30일
I am trying to plot 3 different graphs together using tight_subplot. They all have the same X data, which is time, but when I plot them there is an offset on the time and they are not perfectly aligned and as if the data from one graph was shorter than the other. I have no idea why this could be happening. Here is the code I am using:
ha=tight_subplot(3,1,0.03,0.05,0.095);
hold on
axes(ha(1));
plot(t_ticks(:, 5140:5260),water_level(:, 5140:5260))
title('Spring Tidal Cycle')
ylabel('Water level (m)')
ylim([55 58])
set(gca,'FontSize',14)
set(gca,'Xtick',[])
hold off
hold on
axes(ha(2))
pcolor(t_ticks(:, 5140:5260),z,speed(:, 5140:5260))
shading interp
caxis([0 1.5])
colorbar
set(gca,'YDir','reverse','FontSize',14)
set(gca,'Xtick',[])
c = colorbar;
c.Label.String = 'Horizontal Velocity (m/s)';
ylabel('Depth (m)')
ylim([0 nanmean(depth)+0.88])
hold off
hold on
axes(ha(3))
pcolor(t_ticks(:, 5140:5260),z,dir(:, 5140:5260))
shading interp
colorbar
set(gca,'YDir','reverse','FontSize',14)
t_spring=t_ticks(:, 5140:5260);
set(gca,'TickLength',[0 0],'XTickLabel',datestr(t_spring(:, 1:10:end),'HH:MM'))
c = colorbar;
c.Label.String = 'Direction';
xlabel('Time')
ylabel('Depth (m)')
ylim([0 nanmean(depth)+0.88])
hold off
  댓글 수: 1
dpb
dpb 2018년 10월 30일
Attach some data so folks can try to duplicate symptoms (use .mat file and paperclip) -- saving just the subset and adjusting the indices to match the posted data would probably be better than the whole thing.
Failing that, at least attach the figure (SaveAs .jpg and attach the figure or attach a .fig file) so folks can at least see what you're talking about.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2018년 10월 30일
The problem is likely due to your using the pcolor function. It eliminates the last row and column from the matrix you are plotting. (This is in the documentation under Description (link).)
Run this simple example to see the difference:
Z = rand(5)
figure
pcolor(Z)
set(gca, 'YDir','reverse')
figure
imagesc(Z)
The ('YDir','reverse') makes the comparison easier to see. Note that the ‘last’ row in Figure(1) is the first row in the reversed imagesc plot.
Using the imagesc function, with ('YDir','reverse'), might be the preferable option.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by