[Tex/LaTex] Creating colorful plot using latex terminal of gnuplot

colorgnuplotpdftex

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.

And don't forget to load epstopdf in your preamble:

\usepackage{epstopdf}

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

enter image description here

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'

enter image description here

Best Answer

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}

enter image description here

Example: How to draw a square wave?