Clear Filters
Clear Filters

Export a 3d plot with light in .eps in MATLAB

8 views (last 30 days)
Hi, I'm trying to plot some data with a light to get a 3D effect in my 2D plot but I have a problem when I want to save this image in .eps or .pdf.
When I save the image in eps, it saves a file that I cannot open in Preview or in Illustator (cannot open because of an unknown error). I tried to remove
light;
lightangle(135,20);
and it worked but, of course, the lighting effect disappeared.
Here is my code :
clear all;
close all;
clc;
T0=8.6;
DT=([2.2702, 1.4933, 0.88411, 0.51173, 0.30488, 0.14990, 0.042913]');
T=[3.5, 4, 4.5, 5, 5.5, 6, 7]+0.6';
F=(DT/T0);
[X, Y, Z] = sphere(30);
figure('position', [0 0 300 300]); % 300, 300
hold on;
for ii=1:length(T)
hData(ii) = surf(X/4+T(ii), Y/60+F(ii), Z);
shading interp;
end
hold off;
for jj = 1:length(T)
set(hData(jj), ...
'EdgeAlpha', 1, ...
'EdgeColor', [239, 83, 80]/255, ...
'FaceAlpha', 1, ...
'FaceColor', [239, 83, 80]/255, ...
'FaceLighting', 'gouraud', ...
'EdgeLighting', 'gouraud', ...
'AmbientStrength', 0.8, ...
'DiffuseStrength', 0.1, ...
'SpecularStrength', 1, ...
'SpecularExponent', 0.4 , ...
'SpecularColorReflectance', 1);
end
light;
view(2);
lightangle(135,20);
hxLabel = xlabel('T (K)');
hyLabel = ylabel('F (pN/\mum)');
set(gca, ...
'FontName', 'Helvetica', ...
'FontSize', 15);
set([hxLabel, hyLabel], ...
'FontSize', 18);
set(gca, ...
'Box', 'off', ...
'TickDir', 'out', ...
'LineWidth', 1.5);
set(gcf, 'PaperPositionMode', 'auto');
print('thermalforce.eps', '-depsc');
If somebody can help me, I would be very grateful !

Answers (2)

Mike Garrity
Mike Garrity on 8 Dec 2015
I'm afraid I don't know the whole story on this one, but I know part of it.
If you've got a surface which only contains solid color polygons, then it is pretty easy to translate that into Postscript commands. However, if you have something which makes the color vary across the interior of the polygon, you have a case which can't be represented very cleanly in the PostScript language.
Here's an example.
patch('FaceColor','yellow')
print first.eps -depsc
edit first.eps
If you look at that file, you'll see that it contains commands which draw a triangle and fill it with yellow.
Now try this:
patch('FaceColor','yellow')
l = camlight;
print second.eps -depsc
edit second.eps
If you look at this file, you'll see that it defines a triangle, but then it has the word "clip", followed by a big image. What's going on here is that the camlight command created a 'local' light. This means that the lighting varies across the interior of the triangle. Because this can't be represented exactly in PostScript, it turned the triangle into a clip region, and created a big image with the colors which resulted from the lighting calculations, and painted that "through" the clip mask. This results in the correct image, but it's obviously much more complex than the first case. I expect that this complexity is what's causing the problem here.
I think that in your example, you appear to have an infinite light (which will result in constant shading), but you have FaceLighting='gouraud' and which will also get you into this case.
Try changing FaceColor to 'flat' and see if that helps.
I'll see if I can figure out what's really going on in the more complex case.

Magrini William
Magrini William on 9 Dec 2015
Thank you for your answer. I see what you mean in your two examples but unfortunately, changing 'FaceColor' to 'flat' didn't solve the problem... Even if I put FaceColor and EdgeColor to 'flat' it's still the same problem.
  1 Comment
Mike Garrity
Mike Garrity on 9 Dec 2015
Sorry, my bad. I meant FaceLighting and EdgeLighting, not FaceColor.
The result has little facets like this:

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!