フィルターのクリア

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 Center および File ExchangeSpecifying 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