How can I properly export a figure using the 'patch' command?

Hi all:
I'd like to export a figure in which I use the 'patch' command to shade recessions. However, the image quality drops as soon as I add the recession bands.
I'm using 'exportfig' and convert eps into pdf via ghostscript.
Does anybody have an idea how to fix this problem?
Best, Peter

 Accepted Answer

José-Luis
José-Luis on 8 Nov 2012
Edited: José-Luis on 8 Nov 2012
Looks like your image is transformed to a bitmap. When you use patch, the renderer might be set to OpenGL by default. Try and change your renderer to Painters before exporting your figure. That should ensure that you keep vector graphics. Note that transparencies won't work with Painters.

7 Comments

When I use the 'painters' renderer, the image quality is fine. But then I cannot see the recession bands anymore. Any other suggestions?
Without looking at your code I can only speculate. It might be that 'Painter' does not support the color of the patches you are using, see here. You could always try to change the color of your patches. For instance, this seems to work:
% For this example, there are five triangles (m = 5) sharing
% eleven unique vertices (k = 11).
verts = [2 4; ...
2 8; ...
8 4; ...
8 0; ...
0 4; ...
2 6; ...
2 2; ...
4 2; ...
4 0; ...
5 2; ...
5 0 ];
faces = [1 2 3; ...
1 3 4; ...
5 6 1; ...
7 8 9; ...
11 10 4];
p = patch('Faces',faces,'Vertices',verts,'FaceColor','b','FaceAlpha',0.5); hold on;
plot(1:8,'k','LineWidth',2);
%Saving plot
options.units = 'centimeters';
options.Width = 8;
options.Height = 8;
options.format = 'eps';
options.FontName = 'arial';
options.Renderer = 'painters';
hgexport(gcf,'test.eps',options);
Another option is to use the other renderers, but increase your resolution so as to improve the quality of the picture, i.e. reduce anti-aliasing and pixelation.
Thanks for your help. Ok, now I got it working:
I've changed the color of the patches and used 'uistack' with the 'bottom' option to move the recession bands to the bottom of the current stack. The only thing that's left to do is stack the horizontal axes on top of the recession bands (I turned EdgeColor off, that's probably why both axes are not continuous lines). Any ideas?
This is probably not the most elegant solution but you could plot some new axes and place them on top the old ones:
h = axes;
patch([0 0 1 1],[0 1 1 0],[0.5 0.5 0.5],'EdgeColor','none')
h_over = axes('Position',get(h,'Position'),'Color','none');
Ok, that would work but then I'd also have to add all ticks again as well. Do you know of any command where I can stack the axes above the patches? uistack doesn't work here.
set(h_over,'XTick',[],'YTick',[]);
or
linkaxes([h h_over],'x');
Off the top of my head I can't remember the command you are asking for or whether it actually exists.
set(gca,'Layer','top') worked out. Thanks for your help José-Luis!

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance 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!