2
votes

A dotted diagonal line appears when I print any annotation rectangle in MATLAB.

Example of Issue:

enter image description here

I am attempting to create a annotation rectangle with black face color of arbitrary size on a figure. In the MATLAB figure window, everything displays properly. When I print the figure to a pdf, a diagonal dashed line appears from the bottom left corner to the top right corner. I don't want this line to appear and would like your assistance in removing it from my pdf outputs.


Code:

h = figure( 'Units', 'inches', 'Position', [0 0 11 8.5], ...
    'PaperPosition', [0 0 11 8.5], 'PaperOrientation', 'landscape', 'Resize', ...
    'off','Visible','on', 'Renderer', 'painters');

a = annotation('rectangle','Linestyle', 'none', 'Units', 'inches', ...
    'Position', [.25 .25 .5 .5], ...
    'FaceColor', 'k', 'EdgeColor', 'none');

print(h,'temp.pdf','-dpdf','-r600', '-painters');

Thanks

1
Is it an option to save it as png instead? The diagonal line seems to appear only in pdf. And for me the line is from top left to bottom right... - ThijsW
@ThijsW Unfortunately I need to save as a pdf. I have seen the diagonal appear in both directions. Also, I tried to use the "-zbuffer" option with the print command, which gets rid of the diagonal line but makes all the text on the page look terrible. - RK M
I have tried some different renderers too. '-zbuffer' removes the diagonal line for me, but adds about ten vertical lines to the rectangle. I think '-opengl' was the same, have you tried that one? It does seem to be a renderer problem, but I'm afraid there's only these three options. - ThijsW

1 Answers

0
votes

It seems like the problem is not the output from the matlab renderer, but settings of the PDF viewer. Perhaps you can try changing some settings in the PDF viewer, particularly the settings for anti-aliasing.

I tried opening the pdf file created using your code in an online PDF viewer and the diagonal line was gone.

Another workaround might be to save as .eps instead, and convert the eps file to pdf.

source: http://www.mathworks.com/matlabcentral/newsreader/view_thread/280185