Spikes when saving matlab figure as pdf

1 visualizzazione (ultimi 30 giorni)
Sies Depoorter
Sies Depoorter il 13 Feb 2018
Risposto: Ted Shultz il 2 Nov 2018
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 Commenti
Benjamin Kraus
Benjamin Kraus il 13 Feb 2018
Modificato: Benjamin Kraus il 13 Feb 2018
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 il 13 Feb 2018
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.

Accedi per commentare.

Risposte (1)

Ted Shultz
Ted Shultz il 2 Nov 2018
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);

Categorie

Scopri di più su Electrophysiology in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by