How do I correctly export complex 3D plots as vector image in .pdf format?

14 views (last 30 days)
Hi guys! I need to export a 3D figure with many curves (I will do this procedure many times with other plots for my thesis).
Here the script fragment to perform such operation:
%% 3D CASE
% Load external .mat files
load Customized_colors.mat
load Ast_database
% 3D plot
fig = figure;
% origin of reference frame: Sun
plot3(0,0,0,'.','Color',my_yellow,'MarkerFaceColor',my_yellow,'MarkerSize',30); hold on
text(0+0.1e8,0-0.15e8,'$Sun$','Color',my_yellow,'Interpreter',"latex");
for i = 1:53
plot3([Ast_database(i).orbits_3D.X_km],[Ast_database(i).orbits_3D.Y_km],[Ast_database(i).orbits_3D.Z_km],...
'LineWidth',0.5);
end
axis equal; grid on; box on;
zlim([-0.5e8 0.5e8]);
xlabel('$X$ (km)','Interpreter','latex');
ylabel('$Y$ (km)','Interpreter','latex');
zlabel('$Z$ (km)','Interpreter','latex');
%exportgraphics(fig,'NEAs_3D_orbits.png','Resolution',600); %salva in jpeg
exportgraphics(fig,'NEAs_3D_orbits.pdf','ContentType','vector'); %salva in pdf
Warning: Vectorized content might take a long time to create, or it might contain unexpected results. Set 'ContentType' to 'image' for better performance. Click here to not see this message again.
%%2D CASE
fig = figure;
plot(0,0,'.','Color',my_yellow,'MarkerFaceColor',my_yellow,'MarkerSize',30); hold on
text(0+0.1e8,0-0.15e8,'$Sun$','Color',my_yellow,'Interpreter',"latex");
for i = 1:53
plot([Ast_database(i).orbits_2D.X_km],[Ast_database(i).orbits_2D.Y_km]);
end
axis equal; grid on; box on;
xlabel('$X$ (km)','Interpreter','latex'); ylabel('$Y$ (km)','Interpreter','latex');
xlim([-1.8e8 1.8e8]);
ylim([-1.8e8 1.8e8]);
%exportgraphics(fig,'NEAs_2D_orbits.png','Resolution',600); %salva in jpeg
exportgraphics(fig,'NEAs_2D_orbits.pdf','ContentType','vector'); %salva in pdf
When I run this script, I get the following warning: "Warning: Vectorized content might take a long time to create, or it might contain unexpected results. Set 'ContentType' to 'image' for better performance. Click here to not see this message again."
I do not have this issue when I work with the "plot" function (in that case I plot obly the X and Y coordinates).
Can you help me to correctly export the 3D figure in .pdf format as a vector image?
  1 Comment
dpb
dpb on 2 Oct 2022
exportgraphics is, at the present time, the only builtin facility for doing such and your only choices there are either 'vector' or 'image' and what you get will be what you get and it'll take as long as it takes -- if the image isn't too large/complex and it can succeed at all.
which -all exportgraphics
/MATLAB/toolbox/matlab/graphics/printing/exportgraphics.p
It is a p-file so can't poke at it to see what it does/what librarires it may use, either.
However, note that the warning is not an error; you'll just have to see what you can actually get...

Sign in to comment.

Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by