Spikes when saving matlab figure as pdf

2 次查看(过去 30 天)
Hello
When I plot my figure to a pdf-file, then I get spikes on the figures in the pdf-file which are not present in the original matlab figure. Does anyone know how to get rid of these spikes?
Below you can see the original matlab figure followed by the pdf-file. The spikes are best visible in the right top.
For saving the figure as pdf-file I used the code below:
h=gcf;
set(h,'PaperOrientation','landscape');
set(h,'PaperPosition', [0 0 plotheight plotwidth]);
print(gcf,'-dpdf',title));
  2 个评论
Benjamin Kraus
Benjamin Kraus 2018-2-13
编辑:Benjamin Kraus 2018-2-13
That seems strange. My guess is that the difference has to do with the resolution of your screen compared to the resolution of the file you are outputting.
How are you generating the plots on the right? Are you using bar or stem or plot (or something else)? From the look of the graph, I'm going to guess you are using bar, but you probably should be using stem.
Any chance you can provide sample data and code that reproduces the top-right graph?
If you manually inspect the data, which plot is correct? Are the spikes missing from the top graph, or are they erroneous spikes in the bottom graph?
Sies Depoorter
Sies Depoorter 2018-2-13
I used plot(), and position the figures on the pdf-file with axes().
The data I use are the samples of a deformed sine wave and plot the FFT.
The matlab figure is the correct plot.

请先登录,再进行评论。

回答(1 个)

Ted Shultz
Ted Shultz 2018-11-2
This is a MATLAB bug, and has been happening for a few years. It drives me crazy. For some discussion on this, and a workaround, see: https://github.com/altmany/export_fig/issues/6.
More or less, you save your figure as an eps (print -epsc2 filename.ep) and then run this function on it to fix it:
function fixeps(inname,outname,fixmode)
if nargin==2
fixmode = 'LJ';
end
fi = fopen(inname,'r');
fo = fopen(outname,'w');
tline = fgets(fi);
while ischar(tline)
if (strcmp(tline,['10.0 ML' 10])) % Replace 10.0 miterlimit
switch (fixmode)
case 'LJ'
fwrite(fo,['1 LJ' 10]); % With round linejoin
case 'ML'
fwrite(fo,['2.5 ML' 10]); % With smaller miterlimit
end
else
fwrite(fo,tline);
end
tline = fgets(fi);
end
fclose(fo);
fclose(fi);

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by