Domanda

I create some figures with matlab and export them by using the "Edit -> Copy Figure" with setting "Preserve information (metafile if possible)". I import this in Word 2010. However, if I convert the word document with "save as pdf" the figures have artifacts.

The following image gives you an impression. To the left is Word at 400% zoom, to the right is the pdf with 400% zoom. One can clearly see that dotted lines become straight lines etc. How can I avoid this?

enter image description here

È stato utile?

Soluzione 3

I used the comments here to create my own approach (also with help of: How to set the plot in matlab to a specific size?). So here is my function:

function figureprint(hFig, width, height, res, filename)

%# figure size printed on paper
set(hFig, 'PaperUnits','centimeters')
set(hFig, 'PaperSize',[width height])
set(hFig, 'PaperPosition',[0 0 width height])
set(hFig, 'PaperOrientation','portrait')

%# export
print(hFig, '-dpng', res, filename)

This function is printing a figure to a specific size in cm. E.g.

 figureprint(hFig, 12, 10, '-r1500', 'testPng.png')

So "hFig" is saved as a *.png with a width of 12cm and a height of 10cm. I measured this and this works fine. Optimizations are of course possible.

If you use

set(gca,'LooseInset', get(gca,'TightInset'))

the exponent of the multiply factor for the y values is cutted (when big numbers are plotted) (see image). In this cases you have to modify the values, e.g. like this:

tight = get(gca,'TightInset');
tight(1,4) = 0.08;
set(gca,'LooseInset',tight)

enter image description here

Altri suggerimenti

Expanding a bit on the answer that am304 gave - I just tested the following:

figure
% create a plot with some fine detail:
plot(sin(1./linspace(0.02, 1, 1000)));
% set the "paper size" of the figure (not the size on screen) to 30x20 cm:
set(gcf, 'PaperUnits', 'centimeters', 'PaperPosition', [0 0 30 20]);
% "print" to png with a resolution of 300 dpi
print('-dpng', 'myplot.png', '-r300');

This results in the following picture being saved to disk (cropped to show just detail): enter image description here

The full size picture is just 43 kB - but it is a very high resolution (300 dpi) rendering so you can see the fine details of the plot.

I can insert this picture into a Word document and save it as a pdf. When I then take a screen shot of the pdf, it looks like this:

enter image description here

As you can see - the detail is pretty much all there.

You can use the print function to export your figure to various formats. EPS or TIFF should give good results. I wouldn't use the "Edit -> Copy Figure" if you want high quality figures.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top