1

I'm writing a journal paper, and in this paper, I have to produce many versions of the same graph as I look at the effect of varying different parameters on the variable of interest (in this case the profit).

The following is an example of two of the graphs which I would produce.

The LaTeX source code:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{fullpage}

\pgfplotsset{compat=1.7}

\pagestyle{empty}

\begin{document}

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
    xlabel=Promotion Limit,
    ylabel=Profit,
    legend columns=2,
    legend style={at={(0.5,1.1)},anchor=south}
    ]
  \addplot+[mark=x,thick,blue]
      table [x=promotion.limit,y=optimal,col sep=comma]
      {promotion-limit.txt};
  \addlegendentry{Optimal};
  \addplot+[mark=o,thick,dashed,red]
      table [x=promotion.limit,y=actual,col sep=comma]
      {promotion-limit.txt};
  \addlegendentry{Actual};
\end{axis}
\end{tikzpicture}
\end{center}
\caption{Effect of varying the promotion limit on profit.}
\label{figure:promotion-limit}
\end{figure}

In Figure \ref{figure:promotion-limit},
we see the effect of varying the promotion limit on the profit.

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
    xlabel=Minimum Price,
    ylabel=Profit,
    legend columns=2,
    legend style={at={(0.5,1.1)},anchor=south}
    ]
  \addplot+[mark=x,thick,blue]
      table [x=minimum.price,y=optimal,col sep=comma]
      {minimum-price.txt};
  \addlegendentry{Optimal};
  \addplot+[mark=o,thick,dashed,red]
      table [x=minimum.price,y=actual,col sep=comma]
      {minimum-price.txt};
  \addlegendentry{Actual};
\end{axis}
\end{tikzpicture}
\end{center}
\caption{Effect of varying the minimum price on the profit.}
\label{figure:minimum-price}
\end{figure}

In Figure \ref{figure:minimum-price},
we see the effect of varying the minimum price on the profit.


\end{document}

The contents of promotion-limit.txt are:

promotion.limit,optimal,actual
0,100,100
1,110,105
2,118,108

The contents of minimum-price.txt are:

minimum.price,optimal,actual
8,135,116
9,120,110
10,100,100

The result is:

enter image description here

Question: How do I define a style for these pgfplots, so that I can make changes to the code at a single location, and all the series of graphs will incorporate the changes?

marked as duplicate by Andrew Swann, Martin Schröder, Peter Jansson, Benedikt Bauer, Guido Nov 19 '13 at 9:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.