File Exchange

image thumbnail

Export figure to 3D interactive PDF

version (44.7 KB) by Ioannis Filippidis
Export figure as U3D file or directly to 3D interactive graphics within PDF.


Updated 05 Aug 2017

From GitHub

View Version History

View license on GitHub

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

Cite As

Ioannis Filippidis (2021). Export figure to 3D interactive PDF (, GitHub. Retrieved .

Comments and Ratings (114)

prateek raj gautam

On Matlab 2020 in examples test_spiral.m works but test_fig2u3d_contour_surf giver me error in IDTF to U3D conversion Exit code = 81110008
Exit code = 81110008

What does it mean?
anyone face a similar error and overcame it?

Full terminal output
>> test_fig2u3d_contour_surf
Warning: Axis aspect ratio unequal. Exported U3D will look different.
> In fig2u3d (line 187)
In test_fig2u3d_contour_surf (line 32)
Preprocessing surface No.1
No patch objects found.
No lines found.
No quivergroups found.
No contourgroups found.
Warning: Unequal axes data aspect ratio, to be fixed by scaling the axes. To change this
behavior, edit "fix_daspect = 1;" in fig2u3d to "fix_daspect = 0;"
> In fig2u3d (line 224)
In test_fig2u3d_contour_surf (line 32)
size(cdata, 1) = #points
Number of colors: 64
Number of lines written to IDTF file: 324354
"C:\Users\Prateek\Documents\MATLAB\matlabFig2U3D\fig2u3d\idtf2u3d\bin\win32\IDTFConverter.exe" -input "C:\Users\Prateek\Documents\MATLAB\matlabFig2U3D\fig2u3d\examples\test.idtf" -output "C:\Users\Prateek\Documents\MATLAB\matlabFig2U3D\fig2u3d\examples\test.u3d" -debuglevel 1

Input file name = C:\Users\Prateek\Documents\MATLAB\matlabFig2U3D\fig2u3d\examples\test.idtf
Output file name = C:\Users\Prateek\Documents\MATLAB\matlabFig2U3D\fig2u3d\examples\test.u3d
Profile = 0
Scaling factor = 1.000000
Debug level = 1
Position Quality = 300
Texture Coordinate Quality = 300
Normal Quality = 300
Diffuse Color Quality = 300
Specular Color Quality = 300
Geometry Default Quality = 300
Texture Quality = 75
Animation Quality = 1000
Zero Area Faces Removal = ENABLED
Zero Area Face Tolerance = 0.000012
Exclude Normals = FALSE
Export Option Flags = ffff
Texture size limit = 0

Exit code = 81110008

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

Error in fig2u3d (line 238)

Error in test_fig2u3d_contour_surf (line 32)
fig2u3d(ax, 'test')

Daniel White

Thank you for uploading this function that helps create amazing figures. The directions of @nicholasAWwright work for me on MATLAB R2019b. Before running fig2u3d.m, I used stlread [1] to create triangulations from large .stl files and then plotted them on the same plot using trisurf [2]. When using trisurf, I specified ‘FaceVertexCData’ for each face instead of specifying ‘FaceColor’. This may solve the problems reported by @Frederic K, @Selim Cambazoglu, and @Patrick Sullivan. Alternatively, it looks like Pull request #13 [3] on GitHub would fix this.



I was able to get this package working on 2020a (no guarantees of full functionality) by doing the following:
1. Download package and add to MATLAB path
2. Follow installation instructions for adding the bin folder of the referenced idtf2u3d converter
3. Make the suggested modifications from here:
4. Add these two packages as they seem to be also referenced: and


Many thanks for this great function!

as noted by Mark (few years ago...) it might be helpful to remove black edges from surfaces. I did it by modifying the u3d_pre_surface.m (around line 89). Simply substitute:
renderer = 'SolidWireframe';
renderer = 'Solid';

Nithin Mukundakumar

Nicholas Tiong

Hi, I have an issue processing a .stl file that was converted to a patch in a figure using 3d'fying this patch returns the following errors.

Preprocessing patch No.1
Patch: Fixing face color
FaceVertexCData is already True Color.
Face Vertex Size of patch:

ans =

400000 3

No lines found.
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);

Error in fig2latex (line 48)
fig2u3d(ax, fname)

Error in fig2pdf3d (line 63)
fig2latex(ax, filename, media9_or_movie15, pdforxelatex);

Johannes Bloedt

Thanks a lot for this great work. Does anyone know how to create a time dependend or animated 3D PDF. This would be very helpful for our work.

Archa Rajagopalan


I tried running this code and got the following errors;
Error using arclength (line 104)
at least px and py must be supplied

Error in u3d_pre_line>dots_linestyle (line 166)
[L, dL] = arclength(p);

Error in u3d_pre_line>marker_prep (line 134)
points1 = dots_linestyle(p);

Error in u3d_pre_line (line 80)
[curvertices, curedges, curcolor, curpoints, curpoint_colors] = marker_prep(h);

Error in fig2u3d (line 197)
line_points, line_point_colors] = u3d_pre_line(ax);

Error in fig2latex (line 48)
fig2u3d(ax, fname)

Error in fig2pdf3d (line 63)
fig2latex(ax, filename, media9_or_movie15, pdforxelatex);

Error in Plot_Spline_Vancouver_TAVR (line 1278) - my script
fig2pdf3d(gca, 'test');

If I could get some guidance on how to resolve these, I'd appreciate it!

Scott Ikard

This code does not work. The examples do not work. The instructions are poor and incomplete.

Angel Márquez

Peter Corke

This is a great looking package, but I'm struggling to get started. Am using R2018a.

>> membrane
>> axis equal
>> fig2u3d(gca, 'test3d')
Preprocessing surface No.1
No patch objects found.
No lines found.
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);

At a guess the package is treating graphics handles as numbers, in the old style, not as graphics objects.

Travis Yeager

Does this not work for scatter3d plots? Not sure how to resolve this error:

No surfaces found.
No patch objects found.
No lines found.
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] =


Thanks a lot for sharing this.

Matthew Vowels

Thanks for creating this - awesome!
One strange issue - after typesetting the pdf with latex and viewing it with Preview (Mac OS 10.12.5), the non-3D image has a transparent play symbol - is there a way to get rid of this? The problem doesn't occur when viewing other 3D pdfs, only the one I typeset using the code suggested in this thread.

Patrick Sullivan

I am able to replicate some of the provided examples however having difficulty when trying to export a trisurf.
Here is a simplified example of what I'm trying to export:

[x,y] = meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
ax = gca;
fig2pdf3d(ax, 'test', 'media9', 'xelatex')

I get the following output and error:

Warning: Axis aspect ratio unequal. Exported U3D will look different.
> In fig2u3d at 187
In fig2latex at 48
In fig2pdf3d at 63
No surfaces found.
Preprocessing patch No.1
Patch: Single row FaceVerteXCData, replicating for all faces.
Face Vertex Size of patch:

ans =

88200 3

No lines found.
No quivergroups found.
No contourgroups found.
Warning: Unequal axes data aspect ratio, to be fixed by scaling the axes. To change this behavior, edit
"fix_daspect = 1;" in fig2u3d to "fix_daspect = 0;"
> In fig2u3d at 224
In fig2latex at 48
In fig2pdf3d at 63
#colors = 88200
#points = 225
#faces = 392
Error using single_mesh_resource_str (line 45)
#colors ~= #points and #colors ~= #faces and #colors not empty.

Error in populate_mesh_resource_str (line 28)
cur_mesh_resource = single_mesh_resource_str(faces, points, face_vertex_data, i);

Error in fig2idtf (line 63)
mesh_resources = populate_mesh_resource_str(faces, surface_vertices, face_vertex_data);

Error in fig2u3d (line 233)

Error in fig2latex (line 48)
fig2u3d(ax, fname)

Error in fig2pdf3d (line 63)
fig2latex(ax, filename, media9_or_movie15, pdforxelatex);

Ioannis Filippidis

@James Johnson: Thanks for noting that this dependency isn't included. Nick Fry and Conan Don have noted this below, and Nick Fry has linked to the repository where the function `axes_extremal_xyz` can be found. More specifically at [1]. I opened an issue [2]. In general, please consider opening issues on GitHub, because it makes it easier to keep track of what changes are needed.

@Henrik Larsen: I think that the dependencies you mention are bundled in the distribution [3].


James Johnson

Requires: "axes_extremal_xyz" function which is not a matlab built-in and does not come in the archive linked to.

Ioannis Filippidis


Thanks. I would suggest trying to create a triangulated surface. Also, the points can probably be all included in a single line object, instead of multiple (again with no line visible between them). Another question worth considering is whether plotting 40K distinct points makes any difference to the viewer. If downsampling does not affect the visible quality, then plotting fewer points should improve the situation, reduce the PDF file size, and make viewing within a suitable PDF reader also more efficient.

You may find useful the following functions, at least for the concepts mentioned above:



Good work!

Can you recommend how to use your code to export a scatter3() plot? I have a 3D plot of a cloud of colored points. The underlying shape is a distorted cylinder with holes cut through it. There is no functional relationship between any of the three spatial dimensions and the holes are tricky, so I can't render using surface().

I tried plotting individual line objects with LineStyle='none' and colored markers, but processing was too slow. It was taking about 1 second per line object and 40,000 objects.

Henrik Larsen

@Nick Fry ragerding your problem, I had to additionally download the authors: cell_extrema, plotmd, quivermd, temphold and vectorized_meshgrid before i could make it work. But with that installed everything works like a charm in MATLAB R2017a! Thanks for the tool it's pretty cool.

Ioannis Filippidis

@Jonathan Young: Thanks. Could you please explain why an exception is raised, and what exception it is? Also, `trisurf` is a 3 dimensional plot [1]. Why does setting the difference `d3` between maximum and minimum z coordinates represent a non-flat `trisurf`?

Jonathan Young

@Frederic K and @Selim Cambazoglu, I was able to plot things using trisurf by editing line 71 in view2vws.m to be:
d3 = xyz_minmax(6) -xyz_minmax(5);
d3 = 0;

Ioannis Filippidis

Also, if anyone finds the opportunity to open a pull request on GitHub with a patch for the current Matlab version, that would be helpful. The findings up to now have been collected in this issue: Thanks.

Ioannis Filippidis

@Frederic K: Looking at the examples to remind myself, you might have to do something along the lines of:

p = patch(isosurface(X, Y, Z, F, 0), 'Parent', ax);
set(p, 'FaceColor', 'r', 'EdgeColor', 'r');

In other words, I believe that this is unrelated to `fig2u3d`, which should output the surface as it has been painted. How the surface is painted is determined by the method of plotting it. The default coloring corresponds to the vertical coordinate.

Ioannis Filippidis

@Pan Li: In order to look into the error you mentioned when time permits, I would need to reproduce the error. Could you please open an issue in the repository on GitHub, and provide the code for a minimal working example? Thanks.

Frederic K

Thank you for sharing this. This tool is amazing!

I managed to get everything working, apart from changing the surface color gradient to a uniform color. Any ideas?

I found a hint here, but apparently I am not succesful:


the same error as Selim Cambazoglu!! Please give some advice!

Ioannis Filippidis

@Philip Beng: from a quick look at the code [1] of the stackedplot entry, it appears to be calling `plot, plot3, mesh`. I expect that the figure's contents should be exported as normal (I'm not sure I understand what adaptations would be needed).

Regarding errors with `isnan`, please see the relevant GitHub issues, e.g., [2].



Philip Berg

Is there any way to adapt this script for the Stacked plot function ( Matlab 2015b also getting the error "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);"

Nick Fry

To fix the error in my previous comment download this:
I then also had to download verbatim, acrlength and vnorm which the documentation says are included.

Nick Fry

I am getting the same error as Right Grievous, Hassan and Conan Don.
Undefined function 'axes_extremal_xyz' for input arguments of type 'double'.

Error in view2vws (line 67)
xyz_minmax = axes_extremal_xyz(ax);

Error in fig2u3d (line 242)
view2vws(ax, fname, part_renderers, fix_daspect)

Error in readSTL (line 4)
I have changed rm as per issue #1 which removed that error and I have done the changes suggested by markusha.
Am I simply missing a dependency? I included the 'bin' folder and everything is in the matlab path.

Carlos Melendez

Thank you for sharing this. Excellent job!
I was wondering if anyone managed to export the line widths properties into the .u3d file. In my case, when I export it the .u3d file does not keep the different line widths of the plot. Thank you!

Selim Cambazoglu

Dear all,
First of all, thank you for this great package and the previous commenters for the work around in later Matlab versions. I have managed to make it work with a plot3 but I am having issues with a figure I've generated with trisurf. As I'm a quite new to matlab, I'm not sure if it may work with a trisurf figure. You may find the error I get below. Thank you all in advance.
(Matlab 2014b, Windows 7 64bit)

#colors = 62824756
#points = 12697
#faces = 4948
Error using single_mesh_resource_str (line 45)
#colors ~= #points and #colors ~= #faces and #colors not empty.

Error in populate_mesh_resource_str (line 28)
cur_mesh_resource = single_mesh_resource_str(faces, points,
face_vertex_data, i);

Error in fig2idtf (line 63)
mesh_resources = populate_mesh_resource_str(faces, surface_vertices,

Error in fig2u3d (line 233)

Ioannis Filippidis

@Dale Smith: I do not know what the cause is. Please see also an answer to Marios, dated 11 Dec 2015. More information (e.g., if the exit message says more) would be useful. You could also open a new issue on GitHub, although I expect that this may be an IDTFConverter issue.

You could try using a more recent (forked) version from [1], which claims that:

"This is a fork of ningfei/u3d which is a fork of the v1.4.5 U3D library. It has been updated to support x86 and x64 Windows (VS2008, VS2010, VS2015), Linux and OS X."

If it is a `fig2u3d` issue, then it may relate to the updates needed for compatibility with the graphics API of R2016a (and a few earlier versions). A relevant issue is [2], see also some earlier comments here.
(When time permits, I will test and apply the changes proposed by users to update to R2016b).


Dale Smith

Hello, I am running some of the examples included in the file. However, i get the error: "IDTFConverter executable returned with error"
Is there a known solution?
I'm running linux with MATLAB R2016a 64-bit

Ioannis Filippidis

@Javier, thank you for the information. Please see also my response at the relevant issue:


I confirm that the changes proposed by markusha work for fig2u3d in Matlab R2015a and R2016a. (On a Mac running 10.9.5 (R2015a) or 10.11.5 (R2016a) ).


Ioannis Filippidis

Thanks for the details.


My usage of this package is restricted only to fig2u3d.m (and any functions it calls). In this scenario the changes below allow me to export U3D in R2016b, R2015a, R2014b and R2013b. I do not have access to other releases. It is probably the third change that needs to be chosen correctly for old vs. new ML releases.

Ioannis Filippidis

@Andrea Arenz: Could you please list the functions that you used and worked?

Andrea Arenz

@markusha: With the three changes it works perfectly under Matlab R2013b 32bit und Matlab R2016b 64bit. Great job, thanks a lot!

Ioannis Filippidis

@markusha: Thanks for reporting your patch. Please consider opening a pull request. Are these all the changes needed, or do these suffice specifically for your usage of the package? (if so, please let us know which functions work for you after these modifications). Also, do these changes work with older MATLAB versions?


First off, thank you very much for this nice toolset! My PDF documents have truly benefited from it.

I was able to make this work in R2016b after following changes:
1) in u3d_pre_quivergroup.m change
sh(isnan(sh) ) = [];
sh = [];
2) in u3d_pre_contourgroup.m, same as above
3) in mesh_normals.m, change
normals = get(hp,'VertexNormals');
normals = get(hp,'Vertices');

This works for me. It may or may not work for anyone else.

Michael Boyd

Ioannis Filippidis

@Stefan: Have you added the directories where this package's files are located to your MATLAB path? The installation instructions should be covered by the package's manual (the PDF). If the error persists, then please consider opening an issue at:
In particular, a minimal working example would help (one that triggers the error), together with the relevant environment details (OS, MATLAB, paths, etc.)

Stefan Dawydiak

Thank you very much for this tool, it really does seem to be the only one of its kind! I have the same error that Mohammed had below: I get the error

>In fig2u3d at 187
Undefined function 'u3d_pre_surface' for input arguments of type 'double'.

I have downloaded the Universal 3D Sample Software distribution and copied the bin folder from their into the idtf2u3d folder as per the instructions. Was this what I was actually supposed to do? I am quite inexperienced with MATLAB. I am running MATLAB R2013b.

Andrea Arenz

Thanks for this great tool. Under R2013b I got it working with some minor changes. Now using R2016b nothing is working due to the changed graphics API. Please update it or gibe some hints on how to upate it!

Ioannis Filippidis

From what I can recall, letters are not supported, because they would have to be converted to paths, because .u3d doesn't support fonts (or at least that's what I remember).

Another problem is that letters are not very practical, because they cannot be read, unless they are re-oriented towards the viewing direction.
This is a dynamic operation, and requires two things:

1. JavaScript embedded within the PDF, and
2. a suitable PDF viewer that runs the JavaScript.

Regarding the ticks, they can be replicated, by drawing lines or small spheres at where the ticks are. Those will then be exported.

Nonetheless, there may be a better alternative for presenting this information than adding it as annotations to a 3D document.


Thanks a lot for your work!
I was wondering if there is any way to retain the labels and ticks on the axis.

Ioannis Filippidis

No, `fig2u3d` has not been updated to the graphics API of the latest Matlab release. I would like to update it at some point. As of now, time has not permitted doing so. Please feel free to open pull requests to the GitHub repository.


I'm having the same problem as Jake and Victoria mentioned in 2014 (with Matlab 2015b):

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);

Is there already a fix developed for this issue?

Jim Sell

I am getting an error. It's broken.

Right Grievous

Same error as Hassan and Conan Don


the same error as Conan Don!! any advice

Conan Don

Hi, I have attempted to use the fig2u3d function. However, it seems I am missing some dependencies. I have met with this error.
Undefined function 'axes_extremal_xyz' for input arguments of type ''.

Error in fig2u3d>plot_axes (line 262)
[xyz_minmax, dim] = axes_extremal_xyz(ax);

Error in fig2u3d (line 172)
plot_axes(ax, addaxes)

Please advice

Ioannis Filippidis

@Marios: It looks like some sort of memory error or similar. I do not know the internals of the IDTF converter.

However, do you really need such a resolution ? It is unlikely to be rendered at this resolution on screen, and people will rarely keep zooming until they see all the detail. If the surface is sufficiently smooth, downsampling it is a good practice when the time comes to plot. The same applies to 2d plots. Also, this reduces the file size produced. If some adaptive sampling is needed, then you could try use MATLAB's infrastructure (I assume that it has some way of downsampling surfaces).

Otherwise, please feel free to open a github issue with an example that causes this behavior, together with the specs of your machine and OS.

Ioannis Filippidis

@Andrew: It is the first that a projection issue is noted. The axes are exported here: Please feel free to open a GitHub issue with a minimal working example, including the MATLAB version that you used.

Ioannis Filippidis

@Mark: I do not recall a way to remove the edges. You could try plotting as a mesh with interpolated color, or try to modify the output code (I assume for shading, but please take a look at the IDTF file definition) around here: and here:

Ioannis Filippidis

@Kelaiya: Thank you, for posterity:


Hi Ioannis,

I have a big data matrix A=[5000x7000] to plot as a surface.

If I use your code, i get this message

Model Resources (1) Exit code = 80000000

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

If i "compress the big matrix" (say A=A[A(1:4:end),(1:4:end)], then I can create a pdf.

Any work around on this?



Hi Ioannis, really good code thanks!! I just wondered if anybody had any issues with projection. When am I saving the image it seems to flip the axis. From my image the 0,0 point is in the bottom left but the pdf has this at the top left. Is there anyway to resolve this?


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'.

Konark Kelaiya

@Ioannis, I just opened issue with small example.

Ioannis Filippidis

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

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.

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:

Ioannis Filippidis

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

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).


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)


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?

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?

Patrik Harner

Ioannis Filippidis


This sounds like an insufficient write permission.



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.

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.

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!

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 ?).


@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


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?!


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

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.


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

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.


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.

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.


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);


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.


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!

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:


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.


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?


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

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.


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

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 (


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


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?


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

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.


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.

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.


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.


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.


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!

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.

Martin H. Trauth

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

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.')

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.

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.


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

Sheng Yue

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



Sven Koerner

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!