Math & ScienceI want my gnuplot code INSIDE my LaTeX document!

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
ludachrispeed
Posts: 3
Joined: Fri Jul 24, 2009 5:47 pm

I want my gnuplot code INSIDE my LaTeX document!

Post by ludachrispeed »

And I have found a way to do that with the gnuplottex package, but I can't figure out how to make it produce graphs with color. Here is a minimal working example of what I have:

Code: Select all

\documentclass{article}

\usepackage{gnuplottex}

\begin{document}

\begin{gnuplot}
  set key left
  plot [-2:2] x,x**2
\end{gnuplot}

\end{document}
This can be compiled with pdflatex --shell-escape foo.tex. You need to use shell-escape so that latex can call gnuplot.

Does anyone know of a way I can get the graph to have color?

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

meznaric
Posts: 10
Joined: Mon Aug 10, 2009 7:17 pm

Re: I want my gnuplot code INSIDE my LaTeX document!

Post by meznaric »

This manual should come handy:

http://www.gnuplot.info/docs/node62.html
ludachrispeed
Posts: 3
Joined: Fri Jul 24, 2009 5:47 pm

I want my gnuplot code INSIDE my LaTeX document!

Post by ludachrispeed »

Thank you very much for the link. I tried some and eventually got a gnuplot error
terminal "latex" does not support continuous colors.
I've heard there's a way to do it with PSTricks. I'll keep a lookout.
ludachrispeed
Posts: 3
Joined: Fri Jul 24, 2009 5:47 pm

I want my gnuplot code INSIDE my LaTeX document!

Post by ludachrispeed »

I found a solution to this!

Simply set the terminal type to epslatex. This creates an eps, which is automatically included in the latex file.

Here's a MWE:

Code: Select all

\documentclass{article}

\usepackage{gnuplottex}

\begin{document}

\begin{gnuplot}
  set terminal epslatex color
  set title 'Color graphs with gnuplottex'
  set key left
  plot [0:3*pi][-2:2] sin(x), cos(x)
\end{gnuplot}

\end{document}
compile with latex --shell-escape foo.tex. This of course makes a .dvi file, which can be converted to postscript using dvips, which can then be converted to pdf using ps2pdf.
Post Reply