필터 지우기
필터 지우기

Aligning subplots (width) in a figure

조회 수: 3 (최근 30일)
Jane
Jane 2013년 12월 16일
댓글: Jane 2013년 12월 16일
Hello, I'd like to align the x axes of my two subplots. I can adjust it a little bit, but I'd like it to match up perfectly. Help? Thanks!
%%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...
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');
end

답변 (1개)

David Sanchez
David Sanchez 2013년 12월 16일
Get the size of your image:
[x_size y_size] = size(grayImage);
Then, right after the second subplot:
axis([0 x_size 0 12]);
  댓글 수: 1
Jane
Jane 2013년 12월 16일
Thanks but this gives me
if true
% %%Graphing Fluorescent Intensity
clc;
clear all;
close all;
fontSize = 16;
%
% Calculate the mean gray level.
grayImage = imread('alignedImage.png');
[x_size y_size] = size(grayImage);
meanAlongEachColumn = mean(grayImage);
%
% Plot the aligned image
h=figure;
subplot(2,1,1);
imshow('alignedImage.png');
axis on;
title('Aligned Image', 'FontSize', fontSize);
%
% Plot the Fluorsecent Intensity
subplot(2,1,2);
plot(meanAlongEachColumn, 'k-', 'LineWidth', 2);
title('Fluorescent Intensity', 'FontSize', fontSize);
xlabel('Position');
ylabel('Fluorescent Intensity');
axis([0 x_size 0 12]);
%
% Save plot
saveas(h,'graphfluor2.png');
end

댓글을 달려면 로그인하십시오.

카테고리

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