Aligning subplots (width) in a figure

20 次查看(过去 30 天)
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)

采纳的回答

Jane
Jane 2013-12-5
I figured it out. had to adjust the axis ratios
%%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);
alignPlot = subplot(2,1,1);
topAxs = gca;
photoAxsRatio = get(topAxs,'PlotBoxAspectRatio');
imshow('alignedImage.png');
axis on;
title('Aligned Image', 'FontSize', fontSize);
%
% Plot the Fluorsecent Intensity
subplot(2,1,2);
fluorPlot = subplot(2,1,2);
botAxs = gca;
%
plot(meanAlongEachColumn, 'k-', 'LineWidth', 2);
title('Fluorescent Intensity', 'FontSize', fontSize);
xlabel('Position');
ylabel('Fluorescent Intensity');
% adjust ratios
botAxsRatio = photoAxsRatio;
botAxsRatio(2) = photoAxsRatio(2)/1.88; % NOTE: not exactly 3...
set(botAxs,'PlotBoxAspectRatio', botAxsRatio)
%
% 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',pos1);
% Save plot
saveas(h,'graphfluor.png');

更多回答(1 个)

Alonso Trejo-Mora
Alonso Trejo-Mora 2018-7-31
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.

Community Treasure Hunt

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

Start Hunting!

Translated by