Aligning subplots (width) in a figure
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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]);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!