Publish to PDF - Figures are pixelated/blurry

Hey all,
Today I went to publish a piece of code to PDF and the images were not as crisp as usual. I tried JPEG and BMP and the issue occured in both cases. I'm simply using the publish command, nothing. I've never had a problem before, though I'm not sure I have published any images on R2018a before today... any help would be appreciated
my temporary workaround was to print the images and then import them, which is sub-optimal since it requires making the figures invisible so they don't appear in the published PDF.
EXAMPLE
Here is an example. The first picture is a screenshot of the plot window, which is not blurry. The second picture is a screenshot of the PDF after publishing, which is pixelated. I have attached the PDF for completeness
The issue is produced by the following code, using the following publishing settings
t = linspace(0,1);
plot(t, exp(-t));
title('This title is blurry')
xlabel('This label is also blurry')
ylabel('The whole picture is slighty pixelated')

Answers (3)

OCDER
OCDER on 13 Sep 2018
Edited: OCDER on 14 Sep 2018
New Answer:
Hm, I couldn't find an option to change that resolution. Looked at their Matlab codes publish.m which brought me to their code evalmxdom code that draw the images at fairly low resolution...
%publish.m Line 189-192, draws your code figure at low resolution
% Evaluate each cell, snap the output, and store the results.
if options.evalCode
dom = evalmxdom(file,dom,cellBoundaries,prefix,imageDir,outputDir,options);
end
Here's a workaround to increase the figure resolution before publishing. Maybe someone else know of a better way, or has their own code for publishing high-res codes+figures. Maybe MathWorks should add a feature to increase figure resolution to vector graphics. Anyways, here's the workaround:
t = linspace(0,1);
plot(t, exp(-t));
title('This title is blurry')
xlabel('This label is also blurry')
ylabel('The whole picture is slighty pixelated')
%Increase your figure pixel resolution and font sizes
Gx = gcf;
Gx.Position(3:4) = Gx.Position(3:4)*5;
Ax = gca;
Ax.FontSize = Ax.FontSize *3;
then you can publish your code
publish('mycode.m', 'pdf')
Old Answer:
Use print instead.
print(gcf, 'temp.pdf', '-dpdf')
Make sure to setup the figure PaperPosition, Position, etc properly

7 Comments

I can print to PNG and import in High-Res, the problem is that the automatic publishing of figures is blurry. I would like it to publish my figures automatically like it always has, but without being pixelated.
Can you upload a minimum working code that replicates the issue you are getting? Edit your main question post with this example so others in the forum can test it out.
It looks pretty sharp to me. What do you mean by "publish"? That's a separate function for publishing matlab codes.
t = linspace(0,1);
plot(t, exp(-t));
title('This title is blurry')
xlabel('This label is also blurry')
ylabel('The whole picture is slighty pixelated')
print('myfile.pdf', '-dpdf')
I'm using the "publish" section of the Matlab editor. Many of my classmates don't have the issue, but a few of us do. We are using the "publish" feature that creates a PDF of the entire document, including the code and comments
Seems like a screen resolution issue. See new answer above.
That is a nice workaround, thanks! It's still not ideal, since I have to include those lines for every figure, but it's the best solution for now. Hopefully Mathworks sees this and figures out the issue. I've never had an issue before on this computer, so it must be an issue with 2018a/b

Sign in to comment.

Bump again

1 Comment

Instead of bumping, try asking the MathWorks technical support directly via the Contact Us link on the top right of this page. They usually know other workarounds, and if not, they can add it to the features to improve upon for the next MATLAB Version.

Sign in to comment.

Products

Release

R2018a

Asked:

on 13 Sep 2018

Commented:

on 7 Oct 2018

Community Treasure Hunt

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

Start Hunting!