Graphics, Figures & TablesMissing Axes Labels in Plot from Matlab

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Andreasdreas
Posts: 3
Joined: Thu Dec 06, 2012 12:45 pm

Missing Axes Labels in Plot from Matlab

Post by Andreasdreas »

I have a problem including a graph I have made in Matlab in my LaTeX code. I can get the graph by running the LaTeX code, but the labels of the axis and the scale of the axis is not taken with. Here is what I have done.

My matlab-script is like so:

Code: Select all

XYdata=xlsread('TEK0.xls');
voltage=XYdata(:,2);
time=XYdata(:,1);

figure;
plot(time,voltage,'r', 'linewidth',2);

xlabel('time in seconds');
ylabel('voltage in volts');

print -deps epsFig
When i run this script i get this graph:
Graph produced by Matlab-code
Graph produced by Matlab-code
graf0_matlab.jpg (24.26 KiB) Viewed 15438 times
To get this graph into my LaTeX document i insert the following in the LaTeX code:

Code: Select all

\begin{figure}[H]
\centering
\includegraphics{Kapitler/Forsog/Data/Rectify/data_fra_29_11/epsFig}
\caption{caption}
\end{figure}
And the result is this:
Graph produced by LaTeX -code
Graph produced by LaTeX -code
graph-800.png (15.35 KiB) Viewed 15436 times
I have loaded the graphicx package in my preamble and everything is in the same folder.

I would like to know how I can get the axis labels and scale into my LaTeX figure, if it is not too complicated. I hope you can help me.
Last edited by cgnieder on Thu Dec 06, 2012 1:53 pm, edited 1 time in total.

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Missing Axes Labels in Plot from Matlab

Post by localghost »

Perhaps the EPS file is flawed for some reason. Try to correct it with the »eps2eps« tool from Ghostscript.

If there are no concerns from your side, could you upload the file »TEKO.xls« to the forum server? Probably you need to put it into an archive (*.zip, *.rar or *.tar.gz). There are some LaTeX alternatives for plotting datasets.


Best regards and welcome to the board
Thorsten
Andreasdreas
Posts: 3
Joined: Thu Dec 06, 2012 12:45 pm

Missing Axes Labels in Plot from Matlab

Post by Andreasdreas »

Thanks for the respond.
  1. My teammates can when they run the LaTeX script see the graph with scales and labels on the axis. So its only on my computer the problem is. (We share the files with Dropbox).
  2. Is it possible to get color on the graphs in the PDF created by LaTeX?
  3. I have installed Ghostscript 9.06 for Windows (64bit) (this fits for my PC), but how do I exactly use the eps2eps tool? I have tried searching for it on my PC and opened what came up, then a command window opens and closes again, and the nothing more seems to happen.
The file "TEK0.xls" is attached.

It is not really necessary to get the number and labels on the axis when I run the code on my computer, but it could be nice to solve it though :)
Attachments
ZIP.zip
I hope it can be opened.
(36.64 KiB) Downloaded 351 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Missing Axes Labels in Plot from Matlab

Post by localghost »

Andreasdreas wrote:[…] My teammates can when they run the LaTeX script see the graph with scales and labels on the axis. So its only on my computer the problem is. (We share the files with Dropbox). […]
Are there any significant differences in the working environments (TeX system, operating system, …) that may explain this?
Andreasdreas wrote:[…] Is it possible to get color on the graphs in the PDF created by LaTeX? […]
I should have asked for the EPS file because this question can only be answered if we have the EPS file present and can test its behaviour when included in a document. So, please attach the EPS file to your next post (no need to put it into an archive since the server accepts EPS).
Andreasdreas wrote:[…]I have installed Ghostscript 9.06 for Windows (64bit) (this fits for my PC), but how do I exactly use the eps2eps tool? I have tried searching for it on my PC and opened what came up, then a command window opens and closes again, and the nothing more seems to happen. […]
The eps2eps tool is for the command line and therefore needs some parameters to do its work. Perhaps its better to open the command line window explicitly for a better look at its output. The following line should be enough.

Code: Select all

eps2eps input.eps output.eps
That should give the file "output.eps" in the same folder as "input.eps".

In my last reply I mentioned a LaTeX solution. I took your *.xls file and exported it to *.csv (comma separated values, CSV). This is the format that the LaTeX package pgfplots accepts for plotting datasets. In form of code it looks like this.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\pgfplotsset{
  compat=newest,
  xlabel near ticks,
  ylabel near ticks
}

\begin{document}
  \begin{tikzpicture}[font=\scriptsize]
    \begin{axis}[
      scaled ticks=false,
      xmin=-0.015,
      xmax=0.015,
      xlabel={Time / s},
      xticklabel style={/pgf/number format/.cd,fixed,precision=3},
      ymin=-0.5,
      ymax=0.4,
      ylabel={Voltage / V},
%      ytick={-0.5,-0.4,...,0.5},
      yticklabel style={/pgf/number format/.cd,fixed,precision=1},
    ]
      \addplot[red] table {TEK0.csv};
    \end{axis}
  \end{tikzpicture}
\end{document}
The output is attached. For details see the (quite comprehensive) package manual.
Attachments
TEK0.csv
The CSV file extracted from the provided XLS file.
(35.64 KiB) Downloaded 508 times
Plot by »pgfplots« with the provided dataset.
Plot by »pgfplots« with the provided dataset.
tmp.png (7.14 KiB) Viewed 15371 times
Andreasdreas
Posts: 3
Joined: Thu Dec 06, 2012 12:45 pm

Missing Axes Labels in Plot from Matlab

Post by Andreasdreas »

localghost wrote: I should have asked for the EPS file because this question can only be answered if we have the EPS file present and can test its behaviour when included in a document. So, please attach the EPS file to your next post (no need to put it into an archive since the server accepts EPS).
epsFig.eps
eps-file
(22.1 KiB) Downloaded 487 times
localghost wrote:In my last reply I mentioned a LaTeX solution. I took your *.xls file and exported it to *.csv (comma separated values, CSV). This is the format that the LaTeX package pgfplots accepts for plotting datasets. In form of code it looks like this.
I have tried doing the same thing as you. Putting the following in my document:

Code: Select all

\begin{tikzpicture}[font=\scriptsize]
    \begin{axis}[
      scaled ticks=false,
     xmin=-0.015,
      xmax=0.015,
      xlabel={Time / s},
     xticklabel style={/pgf/number format/.cd,fixed,precision=3},
     ymin=-0.5,
      ymax=0.4,
     ylabel={Voltage / V},
%      ytick={-0.5,-0.4,...,0.5},
      yticklabel style={/pgf/number format/.cd,fixed,precision=1},
    ]
      \addplot[red] table {Kapitler/Forsog/Data/Rectify/data_fra_11_12/TEK0.csv};
  \end{axis}
 \end{tikzpicture}
 \end{document}
And the following to my preamble:

Code: Select all

\usepackage[T1]{fontenc}
\usepackage{pgfplots}%Ting til grafer (sat ind december 2012)
\pgfplotsset{
  compat=newest,
  xlabel near ticks,
  ylabel near ticks
} %Ting til grafer (sat ind december 2012)
The document class is
\documentclass[a4paper,11pt,fleqn,twoside,openright] I don't know if this makes a difference.

The CSV file is attached. When i save the CSv file i choose the punktuation: Westeurope (Windows-1252/WinLatin1).
TEK0.csv
(72.57 KiB) Downloaded 506 times
The following errors comes up:

Code: Select all

! Package pgfplots Error: Sorry, the requested column number '1' in table 'Kapitler/Forsog/Data/Rectify/data_fra_11_12/TEK0.csv' does not exist!? Please verify you used the correct index 0 <= i < N..See the pgfplots package documentation for explanation.Type H <return> for immediate help.... ...sog/Data/Rectify/data_fra_11_12/TEK0.csv};

Code: Select all

! Package PGF Math Error: Could not parse input '"-0,01213","-1,12",,,,,,,' asa floating point number, sorry. The unreadable part was near '"-0,01213","-1,12",,,,,,,'..See the PGF Math package documentation for explanation.Type H <return> for immediate help.... ...sog/Data/Rectify/data_fra_11_12/TEK0.csv};
Is the package manual what comes up when I follow this link http://ctan.org/tex-archive/graphics/pg ... b/pgfplots (which I find when I follow your link). I admit that I haven't really read it through, I find all this pretty confusing. Do I have to download something to use the packages?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Missing Axes Labels in Plot from Matlab

Post by localghost »

You have done some mistakes when exporting your XLS spreadsheet to CSV. See the attached CSV file in my last reply for comparison.
  • Cell content should not be enclosed by quotes.
  • You need to tell the package which column separator you use.
  • The decimal separator has be a period instead of a comma.
  • The additional text has to be erased.
The formats for data files accepted by pgfplots are given in the package manual. The code you copied should be working also in your actual document.

As the only problem with your EPS figure I recognize that it does not show any color. And when I include it into a document I see all axes scales and labels. Nevertheless there seems to be something wrong with it. But a remote diagnosis is not possible because we don't know what you actually did to produce it. In the file (viewed with a text editor) I spotted that it uses the CMYK color space. Perhaps that's the culprit here.

The package is correctly installed on your system. Otherwise you wouldn't receive the error message. So you don't have to worry in this regard.
Post Reply