Graphics, Figures & Tablespgfplots | Usage in LyX

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
heartlet
Posts: 3
Joined: Sat Jul 21, 2012 10:53 am

pgfplots | Usage in LyX

Post by heartlet »

Hello I've been trying to learn how to use pgfplots just over the past few hours. It seems really straight forward and the graphs that I have been able to make look neat.

I thought I might try and polish up some of my own graphs that I have made but I seem to run into some difficulty trying to input files.

So far the problem seems to be isolated with LyX's working directory. (I choose this forum because it might not have been).

I have taken code from the internet so not to mess things up so here is the following:

Code: Select all

\usepackage{setspace}
\usepackage{tikz} 
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=newest}
\onehalfspacing

\begin{filecontents}{datax.dat}
1 3 6
2 4 5
3 3 7
4 1 2
5 1 1
\end{filecontents}

Code: Select all

\begin{tikzpicture} 
\begin{axis}[xlabel={$x$},ylabel={Column Data}]
% Graph column 2 versus column 0
\addplot table[x index=0,y index=2,col sep=space] {datax.dat}; 
\addlegendentry{Column 3}% y index+1 since humans count from 1
% Graph column 1 versus column 0     
\addplot table[x index=0,y index=1,col sep=space] {datax.dat}; 
\addlegendentry{Column 2}
\end{axis} 
\end{tikzpicture}
I was able to run this code fine in LyX. I changed the name of the file that was being created and the file still complied. However, when I tried searching for "datax.dat", I found no match. So I tried this exact code in TeXShop and it works with the file being created.

I placed "datax.dat" file in my working directory (as in LyX -> preferences -> paths -> working directories and changed the name of the test file "datax.dat" to my file and it found nothing. I placed it in the directory of where my file was saved and still nothing.

The error I get is:
"could not read table file"

I have tried \addplot file {file.dat} and I get the error:
"file could not be opened"

Still... The following code works on TeXShop... This makes me believe it is a working directory issue. I tried adding the following path "\foo\bar\file.dat" and nothing.

Any help is extremely appreciated.

Thank you in advanced,

regards,

Charlotte.

---------------------------------
Update: Okay I have found the problem but no fix yet, I got fed up and closed lyx. A popup opened saying "unable to removetemp folder". I went to investigate and there are the files.
(Path: /var/folders/kj/8jc2m9kn5h167wwm3dmvw47h0000gn/T)

However after closing down clicking okay the files delete themselves. I tried changing the directory to another folder and the files still delete themselves.

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply