Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with the gnuplot environment in pgfplots. I already set "--enable-write18" in the argument of pdfLaTeX and added the path of gnuplot.exe to the PATH-variable in the advanced system options.

My problem now is that I can pass code in gnuplot (see picture), below are the 3 lines which I can't pass in the raw-gnuplot-environment in the tikzpicture (see code). What do I wrong? Can someone help, please?

pdfLaTeX-code:

\documentclass[a4paper]{scrartcl}

\usepackage[paperwidth=27cm,paperheight=17cm,margin=0in,showframe]{geometry}

\usepackage{tikz,pgfplots}


\begin{document}



\centering
\begin{tikzpicture}
    \begin{axis} [width=21cm, height=14cm,
    tick label style={font=\large},
    xmin=7700, xmax=7810,
    ymin=0, ymax=0.05,
    axis x line=box,
    axis y line=box
    ]
    \addplot gnuplot [raw gnuplot, id=test, mark=none]{
    set xrange [7700:7810];
    set yrange [0:0.05];
    plot "test.txt" using ($1):($2) with lines;
    };

    \end{axis}
\end{tikzpicture}



\end{document}

gnuplot-picture: gnuplot, works

and finally my data-file: http://www.file-upload.net/download-7764417/test.txt.html

Thank you in advance for your answer!

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You don't tell us what error you're experiencing, so I can only guess at a possible solution: The problem is that, even though you restrict the plot range in gnuplot to x=7700:7810, gnuplot actually writes all the data entries into its output table. It merely marks the points outside the range using an o in the last column. PGFPlots then chokes on the huge amount of data it has to process (150000 points).

What you can do to work around your problem is to use the using syntax in gnuplot to process only a subset of the data. If you say

plot "test.txt" using ($1):($2) every 1:1:100500::105000 with lines;

gnuplot will process all the points starting with the the first block (there's only one block in your data), starting with line 100500, continuing until the last block, ending at line 105000. This range happens to include the values within your desired x range:

\documentclass[border=5mm]{standalone}

\usepackage{tikz,pgfplots}


\begin{document}

\centering
\begin{tikzpicture}
    \begin{axis} [width=21cm, height=14cm,
    tick label style={font=\large},
    xmin=7700, xmax=7810,
    xtick={7700,7725,...,7800},
    axis x line=box,
    axis y line=box
    ]
    \addplot gnuplot [raw gnuplot, id=test, mark=none]{
    set xrange [7700:7810];
    set yrange [0:0.05];
    plot "test.txt" using ($1):($2) every 1:1:100500::105000 with lines;
    };

    \end{axis}
\end{tikzpicture}



\end{document}
share|improve this answer
    
Thank you very much! It works!! I just don't get where the numbers 100500 and 105000 come from? ..because if I try it with another file which has an header and is nearly twice bigger it doesn't work anymore –  Andy Jun 27 '13 at 7:07
    
btw: there is no error shown in the compiler, just an empty tikzpicture in the pdf –  Andy Jun 27 '13 at 7:09
    
@Andy Guess: I think 100500 might be the starting index corresponding to xdata=7700 and 105000 would be index corresponding to xdata=7810 –  texenthusiast Jun 27 '13 at 7:29
    
@Andy Which software generates the test.txt and its header ? Jake's answer is an demo example, it's not suited for a complicated case of data with header files. Hence post it as new follow up Q or update current Q with the structure of header if it can be read by gnuplot ? –  texenthusiast Jun 27 '13 at 7:40
1  
@Jake Thanks. Yes corrected in my answer as Selecting interested range of points instead of down sampling. –  texenthusiast Jun 27 '13 at 14:20

Selecting interested range of points in gnuplot for oversized data files is the good approach while plotting in pgfplots as suggested by Jake. The filename.test.table data size is smaller since selective points are only written by gnuplot engine, thereby easing the load on pgfplots.

Using gnuplottex as an alternative solution to plot entire test.txt data and zooming in the interested x,y range as in Q.

enter image description here

Works with: -shell-escape(TeXLive) or --enable-write18(MiKTeX) enabled and gnuplot 4.4.1

code compiled with: multiple runs of pdflatex,TeXLive distro 2013 on Linux

\documentclass[preview,border=2pt]{standalone}
\usepackage[miktex]{gnuplottex} for MiKTeX
%\usepackage{gnuplottex} for TeXLive on Linux
% http://www.ctan.org/pkg/gnuplottex
\begin{document}   
\begin{gnuplot}[terminal=pdf]
plot [7700:7810] [0:0.05] 'test.txt' using 1:2 with lines;
\end{gnuplot}
\end{document} 

Another approach(not encouraged) is to use LuaLaTeX engine (close relative of pdfLaTeX) with --enable-write18. LuaLaTeX can handle more points( memory capacity) but it's very slow for obvious reasons of data size.

enter image description here

\documentclass[preview,border=4pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8} 
\begin{document}
\begin{tikzpicture}
    \begin{axis}[tick label style={font=\large},
    xmin=7700, xmax=7810,
    ymin=0, ymax=0.05,
    axis x line=box,
    axis y line=box
    ]
    \addplot gnuplot [raw gnuplot, id=test, mark=none]{
    set xrange [7700:7810];
    set yrange [0:0.05];
    plot "test.txt" using ($1):($2) with lines;
    };
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
somehow your code doesn't compile, I get an empty pdf. –  Andy Jun 27 '13 at 7:05
    
I have compiled on Linux with -shell-escape and gnuplot 4.4.1. For MiKTeX (I don't have it as I am on Linux) see if \usepackage[miktex]{gnuplottex} works with --enable-write18 enabled. Remember to run pdflatex twice or thrice until you notice the figure. –  texenthusiast Jun 27 '13 at 7:10
    
@Andy let me know if [miktex] works I should add these words inside Q and clear the comments. –  texenthusiast Jun 27 '13 at 7:31
    
... still doesn't work, I guess I have to check out the gnuplottex package... or get Linux^^ –  Andy Jun 27 '13 at 7:31
1  
@texenthusiast - I think you have a typo; you've written \usepackage[miktex]{gnuplottex} for MiKTeX - while I guess you wanted to comment that last part: \usepackage[miktex]{gnuplottex} % for MiKTeX ... –  sdaau Jul 6 at 4:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.