How can I line up plot edges in subplots?
Show older comments
I want to use subplots to show three orthogonal views of 3D data (latitude,longitude and depth). I need the plots to line up with each other so it looks like it's been "unfolded".
Here is how I tried to do it, with the page size vaguely US letter portrait.
subplot(4,3,[1 2 4 5]);
plot( [Hypo2.lon], [Hypo2.lat], 'r.' );
axis square;
xlim( lonLimits );
ylim( latLimits );
set(gca,'ytick',[]);
subplot(4,3,[3 6]);
plot( [Hypo2.dep], [Hypo2.lat], 'r.' );
xlim( depLimits );
ylim( latLimits );
subplot(4,3,[7 8]);
plot( [Hypo2.lon], [Hypo2.dep], 'r.' );
xlim( lonLimits );
ylim( depLimits );
set( gca, 'YDir', 'reverse' );
And the result:

Is there a way to make the edges of the subplots line up exactly with each other and the two depth axes to be exactly the same size? I suppose I could carefully specify every corner of each plot, but that might make it painful if I want to make changes - such as the subplot going in the bottom row.
Accepted Answer
More Answers (1)
Here's a similar demo/template you can use.
x = randn(1,1000);
y = randn(1,1000).*1.5;
figure()
tcl = tiledlayout(3,3); % 3x3 layout
ax1 = nexttile([2,2]); % Consumes the first 2x2 area
plot(ax1, x, y, 'r.')
grid(ax1,'on')
ax2 = nexttile([2,1]); % Consumes the next 2x1 area
histogram(ax2, y, 10, 'orientation', 'horizontal','FaceColor','r')
linkaxes([ax1,ax2],'y')
grid(ax2,'on')
ax3 = nexttile([1,2]); % Consumes the next 1x2 area
histogram(ax3, x, 10, 'FaceColor','r')
ax3.YDir = 'reverse';
linkaxes([ax1,ax3],'x')
grid(ax3,'on')
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
