views:

227

answers:

1

I'm creating some plots in matlab and then saving it as EPS images.

What is important, I create sets of 4 images, take the 'YLim' value from the first image, and then set it to the other 3 images. I do it to force the same Y-axis limits for each image in the set.

So for the first image, I create some figure, plot something on it, and take it's YLim property:

    f = figure('position', [50, 70, 900, 700], 'Units', 'normalized'); 
    p = plot(s+n, 'k');
    set(gca, 'XLim', [0, 2048]);
    set(gca, 'XTick', 200:400:1800);

    ylim = get(gca, 'YLim');

    saveas(gcf, 'some_name', 'epsc');

Then, for next 3 images, I also create the figure, plot something, and set all needed properties:

    f = figure('position', [50, 70, 900, 700], 'Units', 'normalized'); 
    p = plot(s, 'k');
    set(gca, 'XLim', [0, 2048]);
    set(gca, 'XTick', 200:400:1800);

    set(gca, 'YLim', ylim)

    saveas(gcf, 'some_other_name', 'epsc');

Now, what is strange. Matlab displays these images correctly and all of them have the same Y-axis limits (for example -10:60)

But the saved EPS files have different limits, for example, first has -10:60 but second has -20:60. So, in other words, saved EPS files are not exactly the same as displayed charts.

What am I doing wrong?

+2  A: 

I just copy/pasted your code with s and n defined as rand(2048,1), and I didn't find any problems with the saved EPS files; the y-range was [0,2] in both as expected...

First make sure to double check your actual code, then perhaps you can try setting the PaperPositionMode to 'auto':

set(gcf, 'PaperPositionMode', 'auto')

to enable WYSIWYG printing of figures.

PS: it seems that you are using pixel positions for your figures, which contradicts the 'normalized' units specified, but thats unrelated to your problem.

Amro
It seems that your solution (with setting paper position mode) solved one problem, but created another. I'm generating images for the paper, and I use very large font size (28). After using your solution the limits seem to be set properly, but now the text labels (ticks) of the Y-Axis are clipped.
Gacek
I can only ask you to post the actual code you are using, since the snippets above worked correctly for me, both with and without the PaperPositionMode option (I'm using R2009b on WinXP)
Amro
No need to. I forced the position of axes manually, and now all seems to be OK. Thanks for your help.
Gacek