matlab export plot to vector format

2019-02-12 19:24发布

问题:

All the time previously I was exporting Matlab figures in a raster format (JPG, PNG)

Is there a way to export a plot from Matlab in a vector format (SVG). I need it to inset that plots into LaTeX document.

The only thing, I have found so far is a plugin from mathworks and the answer from stackexchange , but this looks rather too complicated

回答1:

There is also matlab2tikz and matlabfrag which exports to eps with annotation for importing to LaTeX.

Here is an example of mine where I've used matlabfrag.

I've also discussed this with a Mathworks engineer, who agreed that there is not a nice-and-ready tool for this kind of thing, because everybody wants to do different things with it (I already mention two different LaTeX approaches). So imo the best thing to do is to play around with different tools and see which suits you best.

Most of the times I had to tinker a lot with the axes, font size of labels, etc to get it exactly how I wanted (btw adjusting a legend is the greatest hell).



回答2:

I commonly use both Matlab plots in Latex documents. What I usually use is .eps format, is a vector format that Matlab can export quite good. You should edit the most of it that you can in Matlab, with code or manual in the plot. Then just go File -> export setup and click 'expand axes to fill figure', configure whatever you want and export to .eps, then you can import the image to any vector based software, Inkscape or Adobe Illustrator to do final adjustments if needed. Just bump the eps into Latex, it works perfect. Also pdflatex usually converts EPS to PDF, so you can convert it to PDF before from Inkscape or Illustrator if you want to save time.



回答3:

For my publications I save the plot as an EPS (which is vectorized), then do any final touches in Inkscape. Then through Inkscape you can export it to something like SVG. Inkscape has a bunch of tools that are handy for cleaning up a plot (such as simplifying paths and shading).

That's how I made the following T-s diagram:



回答4:

I currently use the FEX package plot2svg to accomplish the task you are mentioning.

It is quite easy to use: after you have added the folder containing the script to your matlab path you can just do

  plot2svg('myplot.svg',gcf);

to save your current figure in svg. (of course you can change gcf (= GetCurrentFigure) to another handle to save other opened figures.)

Indeed, this is the only way I found to export in vector way plots generated by the PDE toolbox.



回答5:

.eps files are easy enough to export and use with LaTeX. I use a function in every project that formats and saves plots to a LaTeX project. It works pretty easily. The 'eps' in the following line can be changed to any Matlab image type.

Something like:

figures = sort(findobj('MenuBar','figure'));
for ii = 1:length(figures)
    saveas(gcf,['Figures/',num2str(ii)],'eps')
end


回答6:

I have exported a matlab figure in .eps then converted the same to .png with GIMP. It turns out that the .png file obtained this way is of much higher quality than the .png files obtained directly from MATLAB figure file by exporting or saveas option. Note that I have used a higher resolution while opening the .eps file to in GIMP. Also I have selected "scale fonts by: auto" in the matlab export setup. I use pdf-latex



回答7:

Matlab vector graphics is broken in the root level since 2014a.
So don't bother to swich from .png format.

Mee my melancholic question with further refferences in matlab Q&A section: https://se.mathworks.com/matlabcentral/answers/290313-why-is-vector-graphics-chopped-into-pieces