Print .eps or .pdf contourf plot with 'edgecolor','none' leaves white lines between levels - need to get rid of them (2019b)

11 views (last 30 days)
Hi, I am having the following problem:
When I create a contourf plot and remove the lines between levels, as I try to print as .eps or .pdf, I end up with many unwanted white lines separating the levels. This does not happen when I print a .png or the number of levels is small.
I have reproduced the problem with the example for contourf given in Matlab website (https://www.mathworks.com/help/matlab/ref/contour.html), see code below.
The choice of colormap does not affect the result. However, I need to use colormap('grey'), and in that case the problem is even more obvious.
Thank you
clc, close all, clear all
Z = peaks;
colormap(gray);
contourf(Z,linspace(min(min(Z)),max(max(Z)),30),'edgecolor','none')
print('test','-dpdf');
print('test','-depsc2');
print('test','-dpng');
disp('DONE')

Accepted Answer

Kiran Felix Robert
Kiran Felix Robert on 8 Oct 2020
Hi Pablo,
The rendered white lines in a PDF file can be removed by force setting the renderer of the figure to opengl and using the saveas function instead of the print function.
The following is an example,
clc, close all, clear all
Z = peaks;
colormap(gray);
contourf(Z,linspace(min(min(Z)),max(max(Z)),30),'LineColor','none')
% To save the figure
set(gcf,'renderer','opengl');
saveas(gcf, 'test', 'pdf')
saveas(gcf,'test','epsc')
saveas(gcf,'test.png')
%%%%%
disp('DONE')
Kiran Felix Robert

More Answers (0)

Categories

Find more on Contour Plots 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!