When I try to print a 3d figure (actually only this figure) in Matlab
as a .eps
format, it does not provide a vector graphics rather provides a rasterized figure as my output instead.
This problem is persistent only with this particular figure, rest of them works great (as expected).
This problem replicated in both 2014b
, 2015a
and 2016b
, as these are the only available software versions, I could not test on others. Moreover, if anybody else suffered from this type of problem?
This is the first time I am facing such a problem, as until now I never had any issues with figure printing (both 2d, and 3d).
Kindly do share your suggestions to overcome this problem.
clc
clear all
close all
warning('off','all')
warning
%% print size def
width = 6; % Width in inches
height = 4.9; % Height in inches
alw = 1; % AxesLineWidth
fsz = 12; % Fontsize
lw = 1.5; % LineWidth
msz = 8; % MarkerSize
set(0,'defaultLineLineWidth',lw); % set the default line width to lw
set(0,'defaultLineMarkerSize',msz); % set the default line marker size to msz
set(0,'defaultLineLineWidth',lw); % set the default line width to lw
set(0,'defaultLineMarkerSize',msz); % set the default line marker size to msz
set(0,'DefaultAxesFontSize',fsz)
% Set the default Size for display
defpos = get(0,'defaultFigurePosition');
set(0,'defaultFigurePosition', [defpos(1) defpos(2) width*100, height*100]);
% Set the defaults for saving/printing to a file
set(0,'defaultFigureInvertHardcopy','on'); % This is the default anyway
set(0,'defaultFigurePaperUnits','inches'); % This is the default anyway
defsize = get(gcf, 'PaperSize');
left = (defsize(1)- width)/2;
bottom = (defsize(2)- height)/2;
defsize = [left, bottom, width, height];
set(0, 'defaultFigurePaperPosition', defsize);
%% loading the data
load('E_fw')
%norm of fw with mass
j=1;
for i=2:1:length(E_m1)
if length(E_m1{i})>1
e_m1{j}=E_m1{i}';
L_m1(j)=length(E_nm1{i});
j=j+1;
end
end
%% plotting m1
t_m1=(0:1:max(L_m1)-1)/8000;
x_m1=1:1:length(L_m1);
for i=1:1:length(L_m1)
B_m1(:,i)=[e_m1{i};ones(max(L_m1)-length(e_m1{i}),1)*inf];
end
[X_ss,Y_ss]=meshgrid(t_m1,x_m1);
g=figure
surf(X_ss,Y_ss,abs(B_m1'), 'LineStyle', 'none', 'FaceColor', 'interp'),grid minor
colormap(flipud(hot))
view([-1, -1, 7])%xaxis from 0 (neg, same for all)
camlight headlight
lighting gouraud
xlabel('op');
ylabel('dop');
zlabel('V');
box on
ax = gca;
ax.LineWidth = lw;
zlim([0 1.6])
xlim([0 0.3])
ylim([1 max(max(abs(Y_ss)))])
set(g,'Units','Inches');
pos = get(g,'Position');
set(g,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3),
pos(4)])
print('map_m1_3d', '-depsc', '-r0');
Since the problem is occurring only for this particular case, I request you to use the data file provided in the link, along with this MWE. The problem has also been reported to Mathworks.
The necessary data file E_fw.mat
is available in the g-drive link inside the data.zip
To all who guided me here (and who may in the future come across the same issue), I received a reply from Mathworks saying that it indeed automatically switches to rasterization mode (they didn't explain how) when certain conditions are violated (as @AndrasDeak explained). So the way to override is to use -painters
extension in the print argument, having the sole disadvantage of the size of the output file blowing up in a nonlinear fashion which explicitly depends on the complexity of the output figure.
I should also say that when the -painters
extension is used to override the internal switch, in my case I ended up with having a .eps
size of around 450 MB which is actually huge when they have to be reused for documentation purposes.