Pixel_95
Pixel_95

Reputation: 984

How to plot in Latex with Gnuplot?

Earlier I have used Gnuplot and created a pdf-file which I then implemented via includegraphics in my Latex-document.

Isn't there a better way to plot directly from the Latex-document with Gnuplot?

Upvotes: 4

Views: 9078

Answers (1)

Pixel_95
Pixel_95

Reputation: 984

Basically u can just follow this Youtube-Tutorial

So here are the Steps:

Step 1: Set environment variables

After having installed MikTex, TexStudio and Gnuplot click on Start -> Rightclick on Computer -> Settings -> Advanced Systemsettings -> Environment variables

Here you have to create 3 new variables:

► PATH
C:\Program Files (x86)\MiKTeX 2.9\miktex\bin;C:\Program Files (x86)\gnuplot\bin

► gnuplot
C:\Program Files (x86)\gnuplot\bin

► GNUPLOT_LIB
C:\Program Files (x86)\gnuplot\demo

Step 2: Edit TexStudio Go to TexStudio and click on Options -> Configure TexStudio -> Commands

here you need to update the upper both commands

► LaTeX
"C:/Program Files (x86)/MiKTeX 2.9/miktex/bin/latex.exe" -src -interaction=nonstopmode %.tex

► PdfLaTeX
pdflatex.exe -synctex=1 -shell-escape -enable-write18 -interaction=nonstopmode %.tex

Step 3: Code with Gnuplot in Latex

\documentclass[a4paper]{scrartcl}
\usepackage[miktex]{gnuplottex}

\begin{document}
\begin{figure}[H]
    \centering
    \begin{gnuplot}[terminal=pdf]
        set terminal pdf enhanced size 14.5cm, 4cm
        set key top left
        set xlabel 'x [1]'
        set ylabel 'y [1]'

        f1(x)=sin(x**2)

        plot f1(x) title 'y_1 = sin(x^2)'
    \end{gnuplot}
    \caption{Plot}
\end{figure}
\end{document}

Upvotes: 3

Related Questions