Problem with different sizes in subplot

15 views (last 30 days)
Chris
Chris on 3 Oct 2015
Answered: Jan on 4 Oct 2015
%crosspost from Newsgroup
Hello everyone!
I want to plot a series of data maps (XY-t maps), 68 time steps of a 84x3 matrix. The aspect ratio of the XY plot is supposed to be 1:1 (equal step size in X and Y), but I can't get this fixed while maintaining the same size for all 68 XY plots. When I fix the aspect ratio of the individual (sub-)plot (daspect), then the size of a variable amount of XY plots gets automatically rescaled (best seen when changing the figure size with the mouse cursor, see example code). Without daspect, I can't be sure that both axis have the right ratio.
I can change the figure size by hand (mouse cursor), the individual subplots will change size and also be perfectly aligned at some point, but that is no sufficient solution for me.
Any idea to resolve my dilemma?
Best regards, CL
Edit: It has to do something with auto-resizing and the large number of subplots. Setting the number of subplots to for example 10 yields a prefect plot. Thus, how do I set the right size for my subplots or at least deactivate the auto-scaling?
Example:
Example code:
%data
m=1;
n=68;
data=rand(84,3,n);
%plotting
h=figure('units','normalized','position',[0.1 0.1 0.7 0.4]);
for i = m:n
subplot(1,n,i);
imagesc(data(:,:,i));
%remove tick marks/label
set(gca, 'XTickLabel', [], 'XTick', [],'YTickLabel', [],'YTick',[]);
%aspect ratio
daspect([1 1 1]);
%add title every few columns
if mod(i,5)==0
title('test')
else
end
end
colorbar;
  1 Comment
Jan
Jan on 4 Oct 2015
I get the same behavior with R2011b, the different renderers and without the titles.

Sign in to comment.

Answers (1)

Jan
Jan on 4 Oct 2015
It seems like this is related to the number of pixels available for a single subplot, such that it is a rounding problem finally.
Either use a single axes and draw the images at different positions. Or use a patch or surf object for each axes, see:

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!