Graphics, Figures & Tablesusing command in gnuplottex

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
nico
Posts: 20
Joined: Tue Jun 08, 2010 10:13 am

using command in gnuplottex

Post by nico »

Hi,

i want to use a command in a gnuplot-environment. I know, that the content is set to the terminal, but is there any way to do this?

Please see the example:

Code: Select all

\documentclass[10pt,a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{gnuplottex}

\begin{document}
\newcommand{\pltSetB}{set xlabel "t [d]"
    set ylabel "c [kg/m^3]"
    set autoscale}
    
\begin{figure}[H]
    \begin{gnuplot}[terminal=pdf]
    \pltSetB
    plot sin(x)
    \end{gnuplot}
\end{figure}
\end{document}
Last edited by nico on Tue Aug 31, 2010 8:38 pm, 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.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

using command in gnuplottex

Post by localghost »

The gnuplot environment of the gnuplottex package changes category codes of characters similar to a verbatim environment to submit a proper script to Gnuplot. Therefore control sequences within this environment won't work.

Consider to generate your plots either with pgfplots (based on pgf/tikZ) or pst-plot (based on pstricks).


Thorsten
nico
Posts: 20
Joined: Tue Jun 08, 2010 10:13 am

using command in gnuplottex

Post by nico »

Hello Thorsten,

first of all: Thanks a lot. I decided to use pgfplots. In my eyes it is much more convenient for my purpose than gnuplot.

I got it working with this approach:

Code: Select all

\documentclass[10,a4paper]{scrartcl}
\usepackage{pgfplots}

\begin{document}

\newcommand{\setWidthCoal}{\textwidth}
\newcommand{\setXLabelCoal}{Tage}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[width=\setWidthCoal,xlabel=\setXLabelCoal]
	\addplot[color=blue,mark=*] coordinates {(1,8)(2,16)(3,32)(4,64)(5,128)(6,256)(7,512)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
It is ok, but it would be much better, if i could use it like that:

Code: Select all

\documentclass[10,a4paper]{scrartcl}
\usepackage{pgfplots}

\begin{document}

\newcommand{\setAxisCoal}{width=\textwidth,xlabel=Tage}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[\setAxisCoal]
	\addplot[color=blue,mark=*] coordinates {(1,8)(2,16)(3,32)(4,64)(5,128)(6,256)(7,512)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
But i get "! Missing \endcsname inserted." with this. Is there a way to fix this?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

using command in gnuplottex

Post by localghost »

Use the \pgfplotsset command for global settings as described in the pgfplots manual.
nico
Posts: 20
Joined: Tue Jun 08, 2010 10:13 am

using command in gnuplottex

Post by nico »

Well...it's not really gnuplottex anymore, but i'm fine with this solution. So maybe it helps other ones too. Thank you, guys!!

Code: Select all

\documentclass[10,a4paper]{scrartcl}

\usepackage{pgfplots}

\pgfplotsset{
B/.style={xlabel=Tage,ylabel=Konzentration der Kohle,legend entries={1,2}}   % Define a own style
}

\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{axis}
	\pgfplotsset{B};     % Set the defined style
    \addplot coordinates {(1,8)(2,16)(3,32)(4,64)(5,128)(6,256)(7,512)};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}
Post Reply