필터 지우기
필터 지우기

Aligning subplots (width) in a figure

조회 수: 15 (최근 30일)
Jane
Jane 2013년 12월 5일
답변: Alonso Trejo-Mora 2018년 7월 31일
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.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by