Why is there an offset in my X axis in my subplots?
7 次查看(过去 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
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!