Spikes when saving matlab figure as pdf

조회 수: 1 (최근 30일)
Sies Depoorter
Sies Depoorter 2018년 2월 13일
답변: Ted Shultz 2018년 11월 2일
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에서 Electrophysiology에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by