How do I improve the image quality of a plot in a published pdf or html?
25 views (last 30 days)
Show older comments
Whether I publish directly as a pdf or from html to pdf, the image quality of the plots is horrible. Can anyone help me out with this?
0 Comments
Answers (1)
Nathan Jessurun
on 10 Dec 2018
Edited: Nathan Jessurun
on 10 Dec 2018
Are you using the vector export option? This makes your graphs and other figures scale perfectly with different zooms. Try this:
fig = figure(1);
plot(1:10, 1:10);
print(fig, 'myFileName.pdf', '-dpdf','-r0')
Unfortunately, this saves the figure at the default figure size. You can change this, though. I made a method to do this -- you can change the scaling parameters as needed to produce a better output.
function saveFig(name, figNum)
fig = figure(figNum);
allAxs = findall(gcf, 'type', 'axes');
fig.Units = 'inches';
fig.PaperPositionMode = 'auto';
fig.Position = [1 1 16 4.5];
fig.PaperUnits = 'inches';
pos = fig.Position;
fig.PaperSize = [pos(3), pos(4)];
for ax = 1:length(allAxs)
% Trim whitespace around figures
outerpos = allAxs(ax).OuterPosition;
ti = allAxs(ax).TightInset;
left = outerpos(1) + ti(1);
bottom = outerpos(2) + ti(2);
ax_width = outerpos(3) - ti(1) - ti(3);
ax_height = outerpos(4) - ti(2) - ti(4);
allAxs(ax).Position = [left bottom ax_width ax_height];
end
print(fig, name, '-dpdf','-r0')
end
Basically you pass the file name and figure number to the function, and it stretches the x axis for signal plots and saves the file as a pdf vector graphic.
See Also
Categories
Find more on Data Exploration 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!