Aligning subplots (width) in a figure
Show older comments
Hello, I'm having trouble having my subplots align (width). Any ideas?
%%Graphing Fluorescent Intensity
clc;
clear all;
close all;
fontSize = 16;
%
% Calculate the mean gray level.
grayImage = imread('alignedImage.png');
meanAlongEachColumn = mean(grayImage);
%
% Plot the aligned image
h=figure;
subplot(2,1,1);
alignedplot = subplot(2,1,1);
imshow('alignedImage.png');
axis on;
title('Aligned Image', 'FontSize', fontSize);
%
% Plot the Fluorsecent Intensity
subplot(2,1,2);
fluorplot = subplot(2,1,2);
plot(meanAlongEachColumn, 'k-', 'LineWidth', 2);
title('Fluorescent Intensity', 'FontSize', fontSize);
xlabel('Position');
ylabel('Fluorescent Intensity');
%
% Find current position [x,y,width,height]
pos1 = get(alignplot, 'Position');
pos2 = get(fluorplot, 'Position');
%
% Set width of second axes equal to first
pos2(3) = pos1(3);
set(alignplot,'Position',pos2)

Accepted Answer
More Answers (1)
Alonso Trejo-Mora
on 31 Jul 2018
Just in case others come across my version of this issue (which seems to be identical to this one), the fix is actually much simpler than this. On the subfigure containing the image, use the command
axis normal;
My image was previously set to "axis image" which made manual adjustment very annoying until I figured this out. I also encourage others to use the computer mouse symbol in every figure's toolbar and click away at some options. There's a lot you can play with and many properties you might not know existed.
Categories
Find more on Blocked Images 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!