Graphics, Figures & TablesGetting Gnuplot to work with LyX

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
davidpage
Posts: 11
Joined: Sat Jan 16, 2010 12:05 pm

Getting Gnuplot to work with LyX

Post by davidpage »

I tried the example in http://www.texample.net/tikz/examples/gnuplot-basics/ but it doesn't work in Lyx. The final output looks something like the following which I guess is that GNUPLOT wasn't configured to run properly:
output.png
output.png (11.26 KiB) Viewed 9091 times
I've tried changing

Code: Select all

pdflatex $$i
to

Code: Select all

pdflatex --shell-escape $$i
in the "converter" setting [for LaTeX (pdflatex) -> PDF (pdflatex)] in Lyx preferences and have also included the tikz package in the preamble. The main text in the Lyx file is nothing but a ERT with the following:

Code: Select all

\begin{tikzpicture}[domain=0:4]
    \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
    \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
    \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
    \draw[color=red] plot[id=x] function{x} 
        node[right] {$f(x) =x$};
    \draw[color=blue] plot[id=sin] function{sin(x)} 
        node[right] {$f(x) = \sin x$};
    \draw[color=orange] plot[id=exp] function{0.05*exp(x)} 
        node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
\end{tikzpicture}
i.e. exactly the code segment in the example. I'd like to have some advice on getting GNUPLOT to work in Lyx, as I have searched all over for that without much success (I'm using Windows XP). Thanks!

p.s. I've read comment #20 there (http://www.texample.net/tikz/examples/g ... sics/#c931) but that doesn't work for me. At least I don't quite understand procedure (b) "rename pgnuplot.exe to gnuplot.exe and put the executable gnuplot.exe in a directory that's included in the windows path environment (I use c: windows system32)" as a standalone exe isn't going to work without the dll's.
Last edited by davidpage on Fri Mar 04, 2011 6:10 am, 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.

gsmm
Posts: 4
Joined: Thu Feb 24, 2011 6:27 pm

Re: Getting Gnuplot to work with LyX

Post by gsmm »

Just now tried. It works.

You need to add the folder path to the "Path" environment variable. To do this
-> Right Click "My Computer" Icon on your desktop
-> Click item "Properties"
-> Click the tab "Advanced"
-> Click the button "Environmental Variables"
-> Double-click the variable entry "Path"
-> open the folder where you installed the gnuplot
-> from the address bar copy the folder path and paste it into the text box for "Path" variable and add a ";" (semicolon) (you must have set the option to show the full path of the folders you view in the folder options dialog)

No need to change the gnuplot executable name. Gnuplot now ships with command line version with the executable name "gnuplot.exe".

You would have got the same output even if you had run with, for instance, with TeXMaker, etc, without adding the executable path to the "Path" environment variable.

best wishes
gs
davidpage
Posts: 11
Joined: Sat Jan 16, 2010 12:05 pm

Re: Getting Gnuplot to work with LyX

Post by davidpage »

Thanks for your suggestion and it works! I was just wondering where to tell my computer that "gnuplot is here" and your method is spot-on. :D
arthurfarias
Posts: 1
Joined: Mon Mar 26, 2012 12:35 am

Getting Gnuplot to work with LyX

Post by arthurfarias »

That's worked for me:
Operational System: Windows 7 64bits
Lyx: 2.0.0
MikTeX: 2.9
GnuPlot: 4.7 (With custom path)

If you don't want to change your path, you can put a gnuplot.bat file into your LaTeX distribution's binary folder with the following content

Code: Select all

@echo off
<path to gnuplot's bin directory>\gnuplot.exe %1
Example:

Code: Select all

@echo off
C:\PROGRA~2\GNU\GnuPlot\bin\gnuplot.exe %1
If you want to change the System Path, i recommend to use this application http://www.redfernplace.com/software-pr ... atheditor/

It's a path editor wich let you know if the current paths on the PATH Environment Variable are valid. Don't forget to save your changes before close.

Another tip is that --shell-escape didn't worked for me, instead of it, I placed -enable-write18.

Example:

Navigate to:
Tools>Preferences...>File Handling>Converters

Select you preefered LaTeX to something converter on the list and after the application command put -enable-write18

Example using XeTeX (Latex (XeTeX) -> PDF (XeTex)):

Code: Select all

xelatex -enable-write18 $$i
Click on Modify, and after, Save.

Try to build the example of this link:

http://www.texample.net/tikz/examples/gnuplot-basics/

Good luck! ;D
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

Getting Gnuplot to work with LyX

Post by topsquark »

Sorry to hijack an old thread, but I'm having the exact same problem as the OP. The only difference is that I'm using Win 11. (I figured I'd just use this one instead of making a new thread and having to explain all the initial stuff again. I'll re-post it if a Mod objects.)

I am using the same TikZ code as the OP and getting the same result that he initially did.

I went through gsmm's instructions in post #2 and added the gnuplot directory to the path in my computer's system path folder. I added "C:\Program Files\gnuplot;" at the end of the PATH prefixes and I noticed that I have a line "Gnuplot -> PDF (graphics)" line in the Converter Definitions list.

I looked at arthurfarias' instructions in post #4 but I'm not sure what to make of that.

Any other suggestions? (I'm not much of an IT guy, so please bear with me!)

-Dan
Post Reply