Get from Ico-github-logo

Highlights from
Export figure to 3D interactive PDF

  • check_file_extension(fnam...
  • clear_file_extension(fnam...
  • create_marker_lines(h, type)
  • cut_line_to_pieces(x, npe...
  • doc_examples
  • draw_crystal_lattice
  • examples
  • fig2idtf(filename, ...
    FIG2IDTF Save figure in IDTF format.
  • fig2latex(ax, fname, medi...
    FIG2LATEX Convert axes to U3D file, generating LaTeX code including it.
  • fig2pdf3d(ax, filename, m...
    FIG2PDF3D Convert axes to PDF with embedded interactive 3D image.
  • fig2u3d(ax, fname, imgtyp...
    FIG2U3D Convert figure to U3D file.
  • get_line_xyz(h)
  • get_quiver_data
  • heart3d
  • idtf2u3d(idtffile, u3dfile)
    IDTF2U3D Convert IDTF to U3D file.
  • idtf_model_nodes(n_meshes...
  • isfilextension(fname, ext...
  • latex2pdf3d(fname, latex_...
    LATEX2PDF3D Compile LaTeX code to PDF.
  • line_pieces(vertices_all,...
    % See also u3d_pre_line, u3d_pre_contourgroup.
  • mesh_diffuse_colors(faces...
  • mesh_normals(points,faces)
    MESH_NORMALS compute mesh normals
  • populate_line_resource_st...
  • populate_mesh_resource_st...
  • populate_point_resource_s...
  • shaders_materials_modifie...
    File: shaders_materials_modifiers.m
  • single_mesh_resource_str(...
    % See also u3d_pre_patch.
  • test_hexagram_shape
  • u3d_in_latex(fname, media...
    U3D_IN_LATEX LaTeX code which includes a U3D file.
  • u3d_pre_contourgroup(ax)
    U3D_PRE_CONTOURGROUP Preprocess contour output to u3d.
  • u3d_pre_line(ax)
    U3D_PRE_LINE Preprocess line output to u3d.
  • u3d_pre_patch(ax)
    U3D_PRE_PATCH Preprocess surface output to u3d.
  • u3d_pre_quivergroup(ax)
    U3D_PRE_QUIVERGROUP Preprocess quiver output to u3d.
  • u3d_pre_surface(ax)
    U3D_PRE_SURFACE Preprocess surface output to u3d.
  • verbatim
    VERBATIM Get the text that appears in the next comment block.
  • view2vws(ax, filename, pa...
    VIE2VWS Saves current view in a views file for LaTeX media9 package.
  • test_fig2u3d_contour_surf.m
    function [] = test_fig2u3d_contour_surf
  • test_spiral.m
    function [] = test_fig2u3d_spiral
  • View all files
4.2 | 16 ratings Rate this file 108 Downloads (last 30 days) File Size: 282 KB File ID: #37640 Version: 1.3
image thumbnail

Export figure to 3D interactive PDF



27 Jul 2012 (Updated )

Export figure as U3D file or directly to 3D interactive graphics within PDF.

| Watch this File

File Information

FIG2U3D saves the figure as a U3D file for inclusion as an interactive 3-dimensional figure within a PDF. Either LaTeX or Adobe Acrobat can be used to embed the U3D file in the PDF.
Development and releases on GitHub:
including binaries there:
(linked also here).

The IDTF2U3D executables available in package from github are originally from:
and can be downloaded from:
If obtaining them from there, then place the "bin" directory in the "idtf2u3d" directory of the fig2u3d distribution.

A VWS file is also created, which contains the current camera view of the axes saved. This file can be used to set the figure's default view in the PDF to be the same with the open figure window in MATLAB.

The media9 LaTeX package can import U3D files with their associated VWS files in a PDF document. It can be found here:

For PDF readers which do not render 3D figures, it is possible to include an alternative 2D image as a substitute to the 3D object. For conveniency, the script saves a 2D image together with U3D file. File type and other options for exporting this 2D image can be specified as additional arguments.

FIG2PDF3D Converts the figure directly to a PDF containing only an interactive 3D graphics object.

Graphics object supported for export include:

   line, surface, patch, quivergroup, contourgroup.

Line colors and marker styles, surfaces and quivers with NaNs and surface shading are supported. Multiple instances of various objects can be plotted in the same axes and exported. Note that some limitations apply, for example filled contours are not yet supported.

Dependency detailed info:

for fig2u3d: idtf2u3d converter executable, download:
and place the "bin" directory in the "idtf2u3d" directory of the fig2u3d distribution.

for fig2pdf3d: latex distribution (e.g. MikTeX, TeXLive, MacTeX etc.)

and media9 (preferred) or movie15 LaTeX package


Remnan, Verbatim: Get The Text Of A Block Comment., Export Fig, Create 3 D Interactive Html File From Matlab Surface, Matlab 3 D Figure To 3 D (X)Html, and Arclength inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Other requirements for fig2u3d: idtf2u3d converter executable for fig2pdf3d: latex distribution (e.g. MikTeX, TeXLive, MacTeX etc.) and media9 (preferred) or movie15 LaTeX package
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (53)
09 Nov 2015 Mark

Mark (view profile)

Hi Ioannis, thanks a lot for this code!
In the pdf file, all the faces in my image have triangulations in them, with black edges around the triangles. Is there any way to remove those black edges? My figure is created using 'patch'.

Comment only
28 Oct 2015 Konark Kelaiya

@Ioannis, I just opened issue with small example.

Comment only
28 Oct 2015 Ioannis Filippidis

@Konark: If you could open an issue on github with a minimal working example, that would help fix the problem. Thank you.

Comment only
28 Oct 2015 Konark Kelaiya

With your script for Surf plot, color is not render as per original figure

surf(X,Y,Z,'FaceColor',[1 0.2 0],'FaceAlpha',0.65,'EdgeColor','none').

When I export this figure to PDF, it renders to solid jet color figure.

Comment only
30 Aug 2015 Ioannis Filippidis

@Patrik: mathwork's comment system just overwrote my answer. Summarizing: trying without the pseudocolor image may work (I do not recall support for images).

If, on the other hand, the image is painted on the surface, then the coloring scheme may be the culprit.

The error you see arises here:
due to the variable `use_vertex_color` remaining undefined, with the warning you see from here:

Comment only
30 Aug 2015 Ioannis Filippidis

@Darcy: Step-by-step instructions can be found in the PDF manual, available here:

Comment only
30 Aug 2015 Ioannis Filippidis

@Darcy: It may be the case that `Cline` draws lines using patches, so these are degenerate patches (1 dimensional), and would need degenerate triangles to be triangulated. Perhaps try modifying to use normal lines, or write your own function for this purpose. I would guess that `Cline` uses patches in order to interpolate color, but not sure whether that is possible with normal line segments too (though cannot recall whether color interpolation is supported).

Comment only
26 Aug 2015 Darcy

Darcy (view profile)

I am currently trying to convert the figure output from Cline (, which i beleive uses patch edges.

The error I receive is:

No surfaces found.
Preprocessing patch No.1
Warning: Patch faces are not triangulated.
> In u3d_pre_patch>delaunay_triangulate_patch_face (line 166)
In u3d_pre_patch>single_patch_preprocessor (line 95)
In u3d_pre_patch (line 70)
In fig2u3d (line 195)
In file (line 1)
Using Delanay triangulation.
Error using delaunay
Input points have invalid dimension.

Error in u3d_pre_patch>delaunay_triangulate_patch_face (line 194)
curtrifaces = delaunay(xproj.');

Error in u3d_pre_patch>single_patch_preprocessor (line 95)
faces = delaunay_triangulate_patch_face(faces, vertices);

Error in u3d_pre_patch (line 70)
[v, f, fvx, r] = single_patch_preprocessor(h);

Error in fig2u3d (line 195)
[patch_vertices, patch_faces, patch_facevertexcdata, patch_renderers] = u3d_pre_patch(ax);

Error in file (line 1)

Comment only
26 Aug 2015 Darcy

Darcy (view profile)

Great resource but I am having difficulty properly configuring all the downloadable content. I'm not sure what I need and basically need a step by step instruction. Any chance you could ellaborate?

05 Aug 2015 Patrik Harner

Hi Ioannis,

First of all, thumbs up for this nicely done project, haven´t found a comparable one.

Second, I´ve got an issue processing the surf axes for a grayvalue image. I´m feeding it a 3D figure + an underlying pseudocolor image, both on the same axe handle of course.
The warning and following error is:

Empty cdata.
size(cdata, 1) = #points
Number of colors: 64
Warning: use_vertex_color: nfvd
otin {npoints, nfaces}
> In shaders_materials_modifiers at 46
In fig2idtf at 78
In fig2u3d at 233
In fig2latex at 48
In fig2pdf3d at

Undefined function or variable "use_vertex_color".

Error in shaders_materials_modifiers (line 49)
shader_resources{1, i} = sprintf(shader_resource_str(use_vertex_color), [shidx, shidx, shidx].');

Any suggestions?

Comment only
05 Aug 2015 Patrik Harner  
22 Jun 2015 Ioannis Filippidis


This sounds like an insufficient write permission.

Comment only
21 Jun 2015 snrlax

snrlax (view profile)


I am having troubles using the package. In matlab 2014a i get the following error:

./IDTFConverter: Permission denied

Error using idtf2u3d (line 111)
IDTFConverter executable returned with error.

Comment only
11 Jun 2015 Ioannis Filippidis

@Rene: The axes themselves can be easily included by drawing lines where the axes are supposed to be. Arrows at the tips can be constructed by placing small cones there.

Regarding text annotation, the u3d format does not natively support text glyphs. For this reason, there is no support for exporting text labels (thus also axis labels).

But including text in 3D graphics is problematic in the first place, because it is practically unreadable, unless either a javascript is embedded in the PDF to keep rotating the text so that it remain orthogonal to the user view direction, or the viewer do this automatically (not the case).

Text is supported by the PRC format, to which you can export from, e.g., Asymptote. So if you really require text, you might want to look into that.

Comment only
10 Jun 2015 Rene Suchantke

This script is very nice but unfortunately not usable for scientific papers as one cannot include the axes - this makes most of my plots (if it isn´t a geometry) meaningless. This would be so nice but I see no way (also not with other programms/scripts) to do so.
Please, please correct me if I´m wrong!

05 Jun 2015 Ioannis Filippidis

@Alexandre: It's been a long time since writing this code, but it appears that changing the `NODE_NAME` here: may have the intended effect (otherwise, the u3d -> idtf converter may be intervening -- though I wouldn't expect such renaming behavior. The only difference appears to be that you write "mesh1", instead of "Mesh1" (perhaps it was capitalized ?).

Comment only
05 Jun 2015 Alexandre

@Ioannis - as a user of your code i have an additonnal question: When the 3Dpdf is created (or before) is it possible to change name of elements on the hierarchy tree? On my 3Dpdf there are only "mesh1" or "line1" and I wanted to change it in order to have the element name that i want. Otherwise code still very useful!! Thanks

Comment only
28 Apr 2015 Davide

Davide (view profile)

It works great on my Matlab2014a, however it has some limitations: it doesn't export the axes, the grid and scattered points...
Anyone has an idea of how to export scattered points?!


26 Feb 2015 Marco Solbiati

Has anybody succeeded in making it work in Matlab R2014b? I'm getting huge troubles.
Thank you.
If you have a solution please contact me:

Thank you

Comment only
22 Feb 2015 Ioannis Filippidis

You seem to be missing the binaries.

Please follow the instructions for downloading all the required dependencies *and* binaries, and placing them so that they will be found (also adding to your matlab path those directories).

For the sources, better to download the tip of the repository as a tarball (or better still, to clone it).

Also, avoid spaces in the path.

Comment only
22 Feb 2015 mohammad

nice program but i got an error...
i initialize folders based on your manual but this error happen when i type fig2pdf3d command :

"Undefined function 'fig2pdf3d' for input arguments of type 'double'."

after that i put all .m files in folder and type the command again.this thime lots of lines appear on the screen and then this error happen :

"No quivergroups found.
No contourgroups found.
Number of lines written to IDTF file: 6862073
"D:\Projects\Matlab\Export to 3d test\bin\w32\IDTFConverter.exe" -input "D:\Projects\Matlab\Export to 3d test\asd.idtf" -output "D:\Projects\Matlab\Export to 3d test\asd.u3d"
The system cannot find the path specified."

please give a hint

Comment only
23 Dec 2014 Ioannis Filippidis

I'm not using MATLAB any more, so I am not familiar with the changes to graphics. I only know that graphics objects, instead of handles are used now. If there is a patch, please send a pull request on github.

Comment only
22 Dec 2014 Victoria

This works great on R2014a.
We now have 2014b, which changes how matlab handles graphics. The issue that Jake has flagged below occurs the graphics objects no longer have 'children' and have to be handled differently. I'm trying to get it to work and I'm having some success, but I'm relatively new to matlab so it's taking time. I'll post an update if I have any luck, but if anyone gets there before me, please go ahead.

14 Oct 2014 Ioannis Filippidis

I am not sure what mathworks decided to change this time. In any case, please feel free to fork the project on github, make the fixes, and send a pull request.

Comment only
14 Oct 2014 Jake

Jake (view profile)

Delighted with this. However, not yet working with the Updated Graphics System on the 2014b Prerelease (can't see why). Is anyone else interested in trying this on the Prerelease?

Undefined function 'isnan' for input arguments of type

Error in u3d_pre_quivergroup (line 63)
sh(isnan(sh) ) = [];

Error in fig2u3d (line 198)
[quiver_vertices, quiver_edges, quiver_colors] = u3d_pre_quivergroup(ax);

07 Aug 2014 Martin

Martin (view profile)

Very nice program, thanks a lot!

Sadly the opacity of every pixel in a surface plot is not copied to the pdf. :(

@Francesco: I changed vol3d to draw the 3d-array without texture mapping. But that didn't fix the problem because the opacity is not copied.

17 Jul 2014 Danielle

I was wondering is there a way to set the line properties (i.e., line width) for the 3D pdf image? Changing the line properties in the figure in Matlab doesn't change the 3D image, other than color. Also is there a way to add the axes labels to the 3D image? Thanks!

13 Jun 2014 Ioannis Filippidis

Material opacity is supported by IDTF. You can try experimenting with changing the alpha value from 1.0 to less than 1.0, i.e., undoing this change:

in this file:

Comment only
12 Jun 2014 Horst

Horst (view profile)

Is there a way to export semi-transparent plots? It seems to always come out opaque but maybe I'm doing something wrong. Thanks a lot.

Comment only
21 Mar 2014 Diogo

Diogo (view profile)

I would like to keep the shading as 'faceted' in the 3d pdf file, but the result looks like the 'interp' shading. How can I have 'faceted' shading in the 3d pdf?
How would I use this to plot oil wells or mining drill holes in 3d pdfs?

Comment only
30 Dec 2013 Alexandre

@ Ionnis: It works!!! Thanks again for your work!

Comment only
21 Dec 2013 Ioannis Filippidis

@Alexandre: If the desired effect is removing the points which have NaN color, then using NaN for those x,y,z coordinates (not the color) should work.

Comment only
20 Dec 2013 Alexandre

Dear Ionnis,
Thank you for this very useful tool!!! Now I can export my matlab figures in a 3D pdf format!! wonderful! However I just have one question: I creat a surf figure using 4 matrix X,Y,Z and Cdata. In my cdata matrix I have some NaN in order to have no color at some specific area. On matlab the figure is ok but when I export into pdf3D areas where I have NaN become darkblue instead of no color!! Any idea to fix it?
Anyway thank you very much again for your work

Comment only
18 Dec 2013 Ioannis Filippidis

No, there is no export for text annotations. One reason is that if I recollect correctly, U3D does not support text representation, so it would have to be exported as lines or surfaces (not very elegant and a lot of "manual" work on top of U3D). I think that text is supported much better by the PRC format ( which is used for example by Asymptote (

Comment only
18 Dec 2013 Jason

Jason (view profile)

Is there by chance a way to export text annotations on the 3d plot to explain what parts of the plot?

27 Jun 2013 Francesco

Hi Loannis,

This is a great tool and I've gotten it to work on my computer for the example files you provided. Unfortunately, it doesn't seem to work when I apply it to a figure produced by the "vol3d.m" function (by Joe Conti), which produces a volume rendering of 3-D data using the matlab "surface" function. I get a lot of outputs in the command line that say "Empty cdata". I don't get an error with fig2u3d.m but when I convert the u3d result to 3d pdf with acrobat, I get an empty white box. If I use fig2pdf3d.m I get the following error "Undefined function or variable "use_vertex_color". Error in shaders_materials_modifiers (line 49)". Do you know what could be wrong?

Comment only
22 Jun 2013 Ben

Ben (view profile)

Hi Ioannis,
I have emailed you my revision. Wish it is helpful.

Comment only
21 Jun 2013 Ioannis Filippidis

Hi Ben,

Thanks for the note, there is an OS X fix I've posted below (04 Dec 2012), but there is something else, please send me the fix. I planned to update the files here when time permitted.

Comment only
20 Jun 2013 Ben

Ben (view profile)

Very good though some modifications are needed in idtf2u3d.m for Mac OS X. If you like, I could send my modified and tested version to you.

24 May 2013 Ioannis Filippidis

Hi Devin,

Including the colorbar is not an implemented feature. The axes are included by plotting them in fig2u3d.m with the function plot_axes.

A suggestion would be to plot the colorbar within the axes (not as it is created by default, i.e., as a separate graphics object). An example which can be adapted according to your needs can be found here:

It looks like it needs some updating, but besides that it has the main idea of a colorbar comprised of patches. Then you can also select its preferred position and orientation.

Thanks for the idea, I will keep it mind for incorporating it in the next release.


Comment only
07 May 2013 Devin Prescott

Hello Ioannis,

This is an excellent and very helpful set of tools. I would like to include my colorbar in the 3D PDFs created with Latex, but have failed in my (limited) attempts. Any suggestions or is this already an option I'm missing? I tried the including the axes in the U3D files but it doesn't seem to pick up the colorbar.


23 Jan 2013 Ioannis Filippidis

Hi dan,

The issue is probably that the missing function is not in your path. You can add all the directories of the package to your path by using the :pathtool" command. Please try to see if its working with other plots (which have surfaces).

Apart from this, this software does not yet support scattergroups. I tried the scatter3 help example and although I got no errors, the geometry exported to the u3d file was essentially empty.

The reason is that some checks are performed. If you successfully run the script for a scatter3 plot, it will report that it did not find any surfaces, lines, patches, quivergroups or contourgroups.
It turns out that scatter3 produces hggroups and the quivergroup and contourgroup export functions look for hggroups. However, they then filter them to see if they are quivers or contours. Otherwise nothing is exported.

In the future there are plans to extend the supported plot types. For the moment all these tests aim to avoid cryptic errors caused by unsupported (or untested) plots. Probably the existing functionality does support scatter3 (i.e., they are only points, so the interface to the output functions will be relatively simple, compared to e.g. quiver output, which has to care about many details). But the wrapper for scatter3 is not yet part of the code.

Comment only
18 Jan 2013 dan

dan (view profile)

Hi Ioannis,
the pdf output of your manual looks really nice.
Unfortunately, it the script always gives me the following error message:
"Undefined function 'u3d_pre_surface' for
input arguments of type 'double'."
I am using scatter3 to generate the matlab figure. Does the script support this?

Thank you for your nice work!

20 Dec 2012 Ioannis Filippidis

Please note that if one is willing to employ another 4 to 5 programs, one of which is a proprietary plug-in costing $99, all of which should be manually handled using the mouse and keyboard, with the obvious issue of having to deal with all the possible incompatibilities and other bugs that may arise as these update and change, then the purpose of writing a compact and clean code for doing the same in code or with one short command at the MATLAB command prompt, with fully open source code (MATLAB excluded) which is free and transparent, is totally defeated.

Comment only
11 Dec 2012 Martin Trauth

I have just (11 Dec 2012) posted an alternative way to create interactive PDFs without LaTeX:

Comment only
04 Dec 2012 Ioannis Filippidis

Hi Mario Garcia and Sheng Yue,

If you are using OSX 10.8+ there may be issues with the environment variables.
Please try this fix in idtf2u3d.m, hope this helps:

%% prepare command
mfiledir = fileparts(mfilename('fullpath') );
curpath = pwd;

% Intel Mac
if ismac
idtf_executable_path = [mfiledir, '/bin/maci/'];

IDTFcmd = './IDTFConverter';

%temp = [getenv('DYLD_LIBRARY_PATH'), ':"', mfiledir, '/bin/maci/"'];
%setenv('DYLD_LIBRARY_PATH', temp)
%IDTFcmd = ['"', mfiledir, '/bin/maci/', IDTFcmd, '"'];

% Linux
if isunix && ~ismac
idtf_executable_path = [mfiledir, '/bin/glx/'];

IDTFcmd = './';

%temp = [getenv('LD_LIBRARY_PATH'), ':"', mfiledir, '/bin/glx/"'];
%setenv('LD_LIBRARY_PATH', temp)
%IDTFcmd = ['"', mfiledir, '/bin/glx/', IDTFcmd, '.sh"'];

% windows
if ispc
win_mfiledir = strrep(mfiledir, '\', '\\');
IDTFcmd = ['"', win_mfiledir, '\\bin\\w32\\IDTFConverter.exe"'];

%% idtf -> u3d conversion
s = [IDTFcmd, ' -input "%s" -output "%s"'];
idtf2u3dcmd = sprintf(s, idtffile, u3dfile);
[status, result] = system(idtf2u3dcmd);
cd(curpath) % go back

if status ~= 0
'IDTFConverter executable returned with error.')

Comment only
04 Dec 2012 Mario García

Hi Sheng Yue,

idtf2u3d does not work correctly on my computer, can you help me?

Error using idtf2u3d (line 97)
IDTFConverter.exe returned with error.

Comment only
09 Nov 2012 Ioannis Filippidis

Hi Delit,

3D PDF files can have text in 3D.
But this depends on which intermediate file is used to import the 3D information to the PDF. In principle it is possible to insert text in the U3D file, but it is much more difficult than in a PRC file. For the moment this code uses U3D files, because it is based on previous work by others, which developed the required intermediate tools. It is possible to create an exporter to PRC, but one would have to look at the code already used for this purpose in Asymptote for example, and convert it to MATLAB, which I would like to try, but is not planned for the near future.

Comment only
09 Nov 2012 Delit

Delit (view profile)

Is it possible to insert scatter and text in the 3D pdf interactive?

Comment only
05 Oct 2012 Sheng Yue

need to change idtf2u3d.m to make it work on my computer.
Still a nice work!

30 Jul 2012 Joachim  
29 Jul 2012 Joachim  
27 Jul 2012 Sven Koerner

Sven Koerner (view profile)

19 Sep 2013 1.2

development on github, bugfixes (including Mac paths)

17 Aug 2015 1.3

link directly to github using matlabcentral itself

Contact us