开发者

Saved EPS image different than plotted chart

开发者 https://www.devze.com 2022-12-20 05:29 出处:网络
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'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?


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 property 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 that's unrelated to your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消