3

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

  • 3
    Instead of directing us to some other site, provide all the data in your post in the form of a [MCVE]. Meanwhile also try [export_fig](https://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig) by Yair Altman. – Sardar Usama May 05 '17 at 13:13
  • @SardarUsama I would prefer to give that, but I am not sure how to upload a data file `.mat` here, because I use some data file to create the figure, here, and only for this particular case the problem is recurring. Anyway, I'll post the MWE now, also please do guide me how to post the necessary data file. – Raaja_is_at_topanswers.xyz May 05 '17 at 13:19
  • Instead of uploading the file, provide its minimal data that reproduces your problem. – Sardar Usama May 05 '17 at 13:24
  • @SardarUsama Yes I understand, the problem is the minimal data file required to reproduce the problem is 7MB, so I gave the `script` here and the data in `g-drive`, however, the particular dataset, I don't know how to give it as an MWE. – Raaja_is_at_topanswers.xyz May 05 '17 at 13:29
  • @SardarUsama Initially I uploaded as bare `.mat` file, that's why your anti-virus flags it as a potential threat. However, it is not, and I rectified the issue in the drive by uploading it in a compressed format. So, I hope it will work good. – Raaja_is_at_topanswers.xyz May 05 '17 at 13:36
  • 1
    Did you also read/try Sardar's suggestion to use `export_fig`? Or the built-in `saveas` which I always use: `saveas(g,'outname.eps','epsc')`. While I would find it *possible* that MATLAB switches to rasterization based on some heuristics, I could (accidentally) produce vectorized 150MB eps files of surface plots in the past without any issues, so I would be surprised if this was the case. – Andras Deak -- Слава Україні May 06 '17 at 02:24
  • @AndrasDeak yes I came here as a last resort (since it is a very narrow downed problem, after trying all, even tried the manual save option). Also, as you have said, in the past it works fine for me, moreover as I mentioned in the question, sadly this only happens for this one set, if I change the data, everything is normal. – Raaja_is_at_topanswers.xyz May 06 '17 at 04:05
  • 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. – Raaja_is_at_topanswers.xyz May 24 '17 at 06:39
  • (Continued) 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. – Raaja_is_at_topanswers.xyz May 24 '17 at 06:51
  • @Raaja I believe you should add this information as an answer (and accept it later when thd system allows it). – Andras Deak -- Слава Україні May 24 '17 at 09:04

1 Answers1

4

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.