4

I have Matlab code that produces an array of subplots that looks like this:

enter image description here

When I save this as an EMF file (normally a vector format) and insert in Powerpoint or view with Inkscape, then zoom in closely on the image, it looks pixelated, and clearly made up of a single encapsulated object as opposed to many small graphical objects:

enter image description here

This is very surprising to me, as I have for a long time been exporting Matlab plots as EMF and integrating those into Powerpoint slides, in order to build there more complex graphs that, as vector graphics, would print well at any size. These imported EMFs would also scale well and look smooth regardless of how much I zoomed into them in Powerpoint.

Can anyone guess why it is that on this occasion, this plot is not saved as a vector graphics but is instead (as it seems) rendered as raster? The code that produces this figure (based on the Matlab commands subplot, line, and scatter) is rather long/inelegant, but I can give details or simplify, if required to find a solution. Thanks!

Other similar threads on this site have not helped fix this.

z8080
  • 571
  • 3
  • 7
  • 23
  • 1
    If possible, remove PowerPoint from the mix. Open the EMF in a vector graphics editing program to find out whether it's actually been exported as a vector or as a raster graphic. If you'd like to post a copy of the EMF on Dropbox or the like and provide a link to it. I'd be happy to have a look. – Steve Rindsberg Jun 17 '18 at 22:12
  • 1
    IIRC inside the PPT you can set the image resolution in its properties try to increase it if the quality change (but not sure if I am not mixing this up with WORD as I did not use those for years). If yes then PPT is handling your EMF as raster but keep it in vector form. If not than it is keeping it as raster. Another option is that EMF is the problem as MS is rather discontinuing EMF instead of repairing security bugs in OS depending on them. To check for that try to use different format like WMF,SVG,... – Spektre Jun 18 '18 at 06:32
  • Thanks to both for your replies. Opening the EMF in Inkscape shows that this plot is indeed exported by Matlab not as vector but as raster graphics. Hard to understand why. The resolution settings inside PPT are already set to maximum, but if the EMF were real vector graphics, this should not have to matter anyway! I know Powerpoint is not optimal for creating graphics, but for now it looks like Matlab, rather than Powerpoint is the culprit!... – z8080 Jun 18 '18 at 10:03
  • 1
    @z8080 metafiles are integer (wmf is 16bit,emf is 32bit) so different resolution might create rounding/scalling/alliasing artifacts even if they are vector. – Spektre Jun 18 '18 at 14:06
  • True, but in this case we're looking at an image that's just stored as raster, and not even harshly-rounded vector – z8080 Jun 18 '18 at 16:55
  • 1
    If you like the saying: "If it's stupid and it works it ain't stupid", then what you can do is to export the Matlab figure into tikz using the package matlab2tikz and the option "standalone" to create a LaTeX document which you then can compile into .eps or whatever filetype you want. Link to package https://se.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz – Nicky Mattsson Jun 27 '18 at 13:32
  • Haha! Will give that a try, thank you! – z8080 Jun 27 '18 at 14:26
  • 1
    @z8080 Have you tried using https://github.com/altmany/export_fig ? – Paolo Jun 27 '18 at 21:40
  • I have - unfortunately, it does not support EMF, which is the format I need in this case. For future reference should anyone have the same need, I ended up saving the Matlab figure as PDF, then I converted to EMF using [this](https://cloudconvert.com/pdf-to-emf) converter. The result EMF is as vector as it gets, so job done! – z8080 Jun 28 '18 at 08:30

1 Answers1

6

I believe I have encountered this issue before. If it is the same as the issue I was facing, it is to do with the renderer being used to save the plot. Although it should automatically select the painters renderer when exporting to vector files, I have had instances where it used the openGL renderer instead, which results in bitmaps being used. I'm not entirely sure why this happens -- it might be the case that for particularly complicated figures, it reverts to openGL to avoid obnoxiously large or complicated vector files.

If you are using the print command, you can force it to use the painters algorithm as follows:

print('-painters',...)

if you're saving using File>Save As..., I believe setting the renderer for the figure should work:

set(figure_handle,'renderer','painters');

For explanation, per the MATLAB documentation:

-opengl' — OpenGL renderer. Use this renderer when saving bitmap images. OpenGL produces a bitmap image even with vector formats, which might limit the extent to which you can edit the image in other applications.

'-painters' — Painters renderer. Use this renderer when saving vector graphics files. If you save to a vector graphics file and if the figure RendererMode property is set to 'auto', then print automatically attempts to use the Painters renderer. If you want to ensure that your output format is a true vector graphics file, then specify the Painters renderer. For example:

print('-painters','-deps','myVectorFile')

If you do not specify the renderer, then print automatically uses the appropriate renderer to produce the output format requested. However, if you set the Renderer property for the figure, then print uses that renderer when generating output.

EDIT: Another option is to use the Copy Figure command (Edit > Copy Figure) -- this should copy the figure as an EMF file, and should obey the figure's renderer settings.

Community
  • 1
  • 1
MrAzzaman
  • 4,734
  • 12
  • 25
  • Thanks! Adding '-painters' to the print input arguments does make the output vector if using the PDF ('-dpdf') format; but does not help if I continue asking for a EMF ('-dmeta') file, which is what I need in order to bring the image to Powerpoint since PDFs cannot be rendered there. – z8080 Jun 25 '18 at 11:01
  • And saving as EMF from the menu does not change the output if using the set command you suggested.. – z8080 Jun 25 '18 at 11:01
  • 1
    What version of powerpoint are you using? In Powerpoint 365 and 2016 I believe you can import images as SVGs, which MATLAB should render as vector images. Alternatively, you could print to an SVG, open it in Inkscape, and export it as an EMF file. – MrAzzaman Jun 25 '18 at 11:13
  • 1
    @z8080 Another option to try is the Copy Figure command -- I've added an edit explaining this. – MrAzzaman Jun 25 '18 at 11:23
  • Thanks - I didn't know you could do that in Matlab, that's cool. However, when pasting that in Powerpoint, it still looks raster, even though I had used the command `set(h,'renderer','painters')` beforehand – z8080 Jun 25 '18 at 12:38
  • 1
    One thing you might try is checking the Copy Options (Edit > Copy Options) and changing the clipboard format to "Metafile", which should hopefully force it to copy as a vector image. If this doesn't work, then I suggest you try my previous suggestion of exporting to SVG as saving as an EMF file from Inkscape. – MrAzzaman Jun 25 '18 at 12:45
  • I've tried both clipboard formats, but the result is the same. I am using Powerpoint 2016, but as I said the problem is with how matlab generates this figure, which, when saved as EMF and opened with Inkscape, will look raster. If I save as SVG, for some reason Inkscape always renders that badly (had tried it before and never liked the output). Thanks again fr your help! – z8080 Jun 25 '18 at 13:14
  • 1
    I've had similar issues with MATLAB badly printing SVG files. One thing to note is that sometimes (in my experience) the files created by File>Save As... are of a higher quality than those produced by `print`. Not entirely sure why they're different, but they are. – MrAzzaman Jun 25 '18 at 13:34
  • For future reference should anyone have the same need, I ended up saving the Matlab figure as PDF, then I converted to EMF using [this](https://cloudconvert.com/pdf-to-emf) converter. The result EMF is as vector as it gets, so job done! – z8080 Jun 28 '18 at 08:30
  • although I would add Powerpoint still renders the EMF blurry at high zoom levels, despite Inkscape recognising it as a true vector image – z8080 Jun 28 '18 at 08:42