Effacer les filtres
Effacer les filtres

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

12 vues (au cours des 30 derniers jours)
Larissa Perez
Larissa Perez le 30 Oct 2018
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 commentaire
dpb
dpb le 30 Oct 2018
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.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 30 Oct 2018
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.

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by