If you are using an operating system other than Windows, some toolboxes may not be functional. SaveFigureAsVectorPDF(FigureHandle, 'withoutaxes.All toolboxes listed in the table below are part of Brown's Matlab TAH license. SaveFigureAsVectorPDF(FigureHandle, 'withaxes.pdf', true) Testing code: %% Generates a graph and saves it to pdf %If you want to see the figure (e.g., for debugging purposes), comment Set(FigureHandleCopy, 'name', 'PDF Figure Preview', 'numbertitle', 'off') Set(FigureHandleCopy, 'PaperPosition', FigurePosition) Set(FigureHandleCopy, 'PaperSize', PaperSize) %Note: these properties do not effect the preview but they are Set(AxisHandle, 'Position', AxisPosition) Set(FigureHandleCopy, 'Position', FigurePosition) HeightWithInset = OldAxisHeight + OldAxisInsetTop + OldAxisInsetBottom ĪxisPosition = WidthWithInset = OldAxisWidth + OldAxisInsetLeft + OldAxisInsetRight %% Set positions and size of the figure and the AxisįigurePosition = OldAxisInset = get(AxisHandle, 'TightInset') OldAxisPosition = get(AxisHandle, 'Position') %Note that the axes and title are contained in the inset %% Get old axis position and inset offsets Set(FigureHandleCopy, 'PaperUnits', cUnit) ![]() % It doesn't matter what unit you choose as long as it's the same for %note that every plot has at least one child figureĮrror('This function currently only supports plots with one child figure.') NumberOfChildFigures = length(ChildAxisHandles) % view but I am not sure how to prevent that.ĬhildAxisHandles = get(FigureHandleCopy, 'Children') % I would prefer it if the figure did not briefly flicker into % it must be visible otherwise Matlab will just ignore attempts %NOTE: Do not set this figure to be invisible, for some bizarre reason %Make a copy of the figure so we don't modify the properties of theįigureHandleCopy = copy(InputFigureHandle) %% Copy the input figure so we can mess with it = size(InputFigureHandle) Įrror('This function only supports one figure handle.') Įrror('No file path provided to save the figure to.') The code below will export any single plot figure handle as a vector PDF, either with or without axes.įunction SaveFigureAsVectorPDF(InputFigureHandle, OutFileName, ShouldPrintAxes) ![]() Note that unlike Antonio's script, this only works on figures without subplots. I made something based on his script and added the option to export only the plot box (omitting the axes). I liked method the best but it still left too much whitespace, and I was looking for a single plot solution that exported to vector pdfs for usage in LaTeX. % rectangular convex hull of the plot, and increase the size of the figure % vertical negative offsets equal to the lower-left coordinates of the % to control the location on printed page place it using horizontal and % use the PaperPosition four-element vector % printer driver to honor the figure properties % ensure that paper position mode is in manual in order for the % set the paper to the exact size of the on-screen figure using ![]() % compute the rectangular convex hull of all plots and store that info % the same unit system as paper (centimeters here)īounds(i,:)=[pos(1)-inset(1) pos(2)-inset(2). % generate all coordinates of corners of graphs and store them in % bounds will contain lower-left and upper-right corners of plots plus one % first use the same non-relative unit system for paper and screen (see However, if you really want a pdf figure like a Matlab-generated eps, that is, only the rectangular convex hull of the plot (or set of subplots), here's the more sophisticated version: function printpdf(h,outfilename) Set(h, 'PaperPosition',) įor example, to print the current figure you can call it with: printpdf(gcf,'trash') This function uses a figure handle and a string to print the stuff in a pdf file without the huge margins.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |