Filter löschen
Filter löschen

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

12 Ansichten (letzte 30 Tage)
Larissa Perez
Larissa Perez am 30 Okt. 2018
Beantwortet: Star Strider am 30 Okt. 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 Kommentar
dpb
dpb am 30 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 30 Okt. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by