Graphics, Figures & TablesSingle plot missing after eps-to-pdf conversion

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
glennib
Posts: 3
Joined: Thu Aug 17, 2017 10:03 pm

Single plot missing after eps-to-pdf conversion

Post by glennib »

Hello,

I'm creating an EPS-file from a Matlab figure by using the equivalent of the following Matlab code:

Code: Select all

fig = figure;
subplot(2,1,1)
plot(X_data_1, Y_data_1)
grid on
ylabel('label')
title('title')
subplot(2,1,2)
plot(X_data_2,Y_data_2)
grid on
ylabel('label')
xlabel('label')

print(fig, 'fig_name', '-depsc', '-tiff')
Then I'm using

Code: Select all

\includegraphics{fig_name.eps}
to show it in my LaTeX document. This creates a fig_name-eps-converted-to.pdf file.

The original fig_name.eps file displays all the plots, I've viewed it in Acrobat, SumatraPDF and Inkscape, which all show all plot lines perfectly fine. However, when I open the pdf file which was generated, only the first plot shows, not the plot in the second subplot. Let me provide the differences:
side-by-side-screenshot.PNG
side-by-side-screenshot.PNG (99.9 KiB) Viewed 4595 times
I've uploaded both files + a screenshot of the difference.

One fix was to append the following lines to the Matlab code before the printing:

Code: Select all

hold on
plot(5,-20,'sm') % Adds a single point of a magenta colored square to the last plot.
This makes the actual data (data_2) visible in the pdfs, and in my latex document (but not the random data point). So it seems like the last dataplot does not show after conversion.

Does anyone know what's wrong here?

EDIT: I also tried with the codec -depsc2, did not help.
Attachments
pose.eps
(171.6 KiB) Downloaded 468 times
pose-eps-converted-to.pdf
(16.34 KiB) Downloaded 250 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Single plot missing after eps-to-pdf conversion

Post by mas »

I converted the eps file you included using epstopdf on my linux box. The resulting pdf shows all the plots. When I looked at the pdf files, I noticed these differences:

Your file:

Code: Select all

<</Producer(MiKTeX GPL Ghostscript 9.19)
My converted file:

Code: Select all

<</Producer(GPL Ghostscript 9.21)
I do not know if the Ghostscript version matters. You can explore that. I am attaching the converted file and a screen shot.
pose.png
pose.png (47.54 KiB) Viewed 4590 times
Attachments
pose.pdf
(21.69 KiB) Downloaded 249 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
glennib
Posts: 3
Joined: Thu Aug 17, 2017 10:03 pm

Single plot missing after eps-to-pdf conversion

Post by glennib »

Thanks for exploring that for me. I forgot to mention my setup. It's Windows 7 with MiKTeX. Maybe there's a bug there.

Not sure if it's possible to use a different Ghostscript conversion tool. I will just add an invisible data point to each plot to hotfix the problem as I'm racing to complete my master's thesis now, but I might investigate more later.

Thanks again for your help.
thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

Single plot missing after eps-to-pdf conversion

Post by thomasb »

If you make time in learning tikzpicture addplot, it might worth the effort : http://pgfplots.sourceforge.net/gallery.html

addplot can be given a text file with data in columns that you could export from Matlab.

Example : \addplot[mark=none] table [x index=0, y index=1]{mydata.txt};
which means :
  • \addplot : the command
  • [mark=none] : no dots
  • table : if your file has more than two data columns (otherwise, file instead)
  • [x index=0, y index=1] : first column is x, and second column is y
  • {mydata.txt}; : your file name.
Example for a two columns file :
\addplot[mark=none] file [skip first]{mydatafilewithtwocolumns.txt};
which means :
  • \addplot : the command
  • [mark=none] : no dots
  • file : if your file has two data columns (otherwise, table instead)
  • skip first : skips the first line (like : Day Temperature)
  • {mydatafilewithtwocolumns.txt}; : your file name.
Grids, axis, labels are a piece of work too.
If you convert your Matlab file in raw data columns, I give an eye...
glennib
Posts: 3
Joined: Thu Aug 17, 2017 10:03 pm

Single plot missing after eps-to-pdf conversion

Post by glennib »

I will definitely look into that for later research documents. Great tip, thank you.
Post Reply