MATLAB Answers

force print() to vectorize axes/text and rasterize the rest

2 views (last 30 days)
David Ho
David Ho on 6 Apr 2016
Edited: David Ho on 18 Aug 2020
I have a 3-D plot with large number of data points (100,000+) that I need to export to eps into Latex for publication. I have tried numerous options but none of them are satisfactory.
First the data points are randomly generated inside a non-rectangular domain (the domain is a triangle in R^2). I tried interpolating into a rectangular grid but the edge artifacts are not desirable. So I resorted to generate a large number of points to sufficiently show the features of the surface (objective function).
The default `print -depsc2` in matlab2015a is taking too long to render the output. I looked into epscombine and figure2eps. Epscombine is outdated as it looks for a tag in the eps file that is not used in recent matlab. Figure2eps relies on epscombine under the hood but it fails to detect any surfaces or patches as my figure only contain lines.
Is there an option in print I can use to perform mixed mode export (i.e. vectorize text/axis and rasterize the rest)?
Here is the relevant part of the code, where the z direction is color coded based on the function value.
% group points
sr_min = min(sum_rate);
sr_max = max(sum_rate);
diff_sr = sr_max-sr_min;
n_colors = size(cmap,1);
lvls = sr_min:diff_sr/64:sr_max;
figure;
for cc = 1:n_colors,
ii = find( sum_rate <= lvls(cc+1) & sum_rate >= lvls(cc));
h{cc} = plot3(px(ii),py(ii),sum_rate(ii),'.','Color',cmap(cc,:)); hold on;
end
Update (4/7/2016): Using Matlab 2015a, I can hide the axes/text and grid lines, print the data using -opengl, and do the reverse (hide data, make axes/text and grid lines visible) and print using -painters (see code below). When I manually merge the eps files, depending on which order I put the components in, one always overwrite the other completely. So this hack is not working, a more sophisticated way is needed.
%%export graph
ax = gca;
ax.Title.Visible='off';
ax.XColor = 'none';
ax.YColor = 'none';
ax.ZColor = 'none';
print -depsc2 -opengl data.eps
%%export the axes % with transparent background
set(gca,'color','none')
set(gcf,'color','none')
for cc = 1:n_colors,
set(h{cc},'visible','off') % hide the data
%set(h{cc},'visible','on') % hide the data
end
grid off
ax.XColor = 'k';
ax.YColor = 'k';
ax.ZColor = 'k';
ax.Title.Visible='on';
print -depsc2 -painters axes.eps
%epscombine('axes.eps','data.eps','test.eps')
disp('eps generated');
Regards, David

  2 Comments

enduro
enduro on 18 Aug 2020
I have a similar problem. Did you find a solution to vectorize labels and axes but not the actual data?
David Ho
David Ho on 18 Aug 2020
Here is an example that was provided to me from matlab support (see raster_eps_example.m).
However, I ended up using the SurfcePlotSolution.m. It required generating fewer data points (if they can be generated evenly on the surface) and filling the surface using triangulation.
Hope this helps.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!