# Creating colorful plot using latex terminal of gnuplot?

Most output terminals of gnuplot draw different lines in a plot in different colors. I'm trying to create a plot inside my pdf document using gnuplot's latex terminal and the lines are only distinguishable by linestyle.

What do I need to do to get the lines colored?

I use pdflatex.

From this example:

\documentclass{scrreprt}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[miktex]{gnuplottex}
\usepackage{graphicx}

\begin{document}
\begin{figure}[htbp]
\centering
\begin{gnuplot}[terminal=latex]
plot [0:2*pi] sin(x) title 'Sine', cos(x) title 'Cosine'
\end{gnuplot}
\end{figure}

\end{document}


I get this result:

@texenthusiast provides part of the solution: set the options [terminal=epslatex,terminaloptions=color] when using gnuplot.

The lines in the plot will now be colored but still have different styles.

To give them the same style you can now use something like

set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2
plot [0:2*pi] sin(x) with lines ls 1 title 'Sine', cos(x) with lines ls 2 title 'Cosine'


-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  texenthusiast Aug 23 '13 at 15:15
may be terminal=pdf should give default gnuplot colors –  texenthusiast Aug 23 '13 at 15:16
@texenthusiast It surely will, but then gnuplot does the typesetting instead of TeX, so that TeX macros in labels or titles will fail. –  Marco Aug 23 '13 at 15:22
Sorry, a bit rusty, Use [terminal=epslatex,terminaloptions=color] which can get TeX typset the labels and title as @Marco said. –  texenthusiast Aug 23 '13 at 15:32
With latex terminal export it gives out picture environment without any colors and does not understand the default colors of gnuplot. I will have to see if gnuplot can do it or exported .tex file has to manually edited to add color packages and userdefined colors –  texenthusiast Aug 23 '13 at 16:49

Out of the many( latex, tex, epslatex,pstricks pdf and lua/tikz) gnuplot terminal exports available epslatex seems reasonable.

Using [terminal=epslatex,terminaloptions=color] seems to be optimal since .eps plot is taken from gnuplot and TeX is used to typeset text in labels/titles to give nice consistency. But for more options gnuplottex might give details.

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[miktex]{gnuplottex} % for MiKTeX,pdflatex -shell-escape enabled
%\usepackage{gnuplottex} I have used this line to compile on TeXLive 2013
\usepackage{graphicx}
%\usepackage{epstopdf} % for MiKTeX,pdflatex -shell-escape enabled
\begin{document}
\begin{figure}[htbp]
\centering
\begin{gnuplot}[terminal=epslatex,terminaloptions=color]
plot [0:2*pi] sin(x) title 'Sine', cos(x) title 'Cosine'
\end{gnuplot}
\end{figure}
\end{document}


Example: How to draw a square wave?

-
For completeness: Gnuplot 4.6 provides also a cairolatex terminal (either with eps or pdf output) and a context terminal. –  Christoph Aug 23 '13 at 22:46