Setting a default plot in Tikz

709 views Asked by At

So I have this code :


  \pgfplotsset{myaxis/.style={ 
    axis x line=left, 
    axis y line=left, 
    grid=both,
    title={lifeguards needed for swimmers},
    xlabel={number of lifeguards}, 
    ylabel={number of swimmers}, 
    grid=both,
    ytick={0,10,...,80},
    yticklabels={0,10,...,80},
    xmin=1, xmax=7, 
    ymin=0, ymax=80
    }
  }

  \def\baseplot{\addplot [only marks,color=blue,mark size=5pt] coordinates {(2,20) (4,40) (6,60)};}

  \rc[0.8]{
    \begin{tikzpicture}
      \begin{axis}[myaxis]
        \baseplot
      \end{axis}
    \end{tikzpicture}
  }

(\rc just does a center/resize box)

It works, but feels hacky because I am forcing a \def . I have a bunch of these I am plotting with just a few different things on each of those base plots. I know I can use :

\tikset{base graph/.pic={}}

and then

\pic {base graph};

But not here as I suspect I have to do some kind of pgfplotsset?

1

There are 1 answers

0
Cliff Stamp On

Figured it out :


  \pgfplotsset{mygraph/.code={
      \addplot [only marks,color=blue,mark size=5pt] coordinates {(2,20) (4,40) (6,60)};
    }
  }

invoked with

\pgfplotset{mygraph};

You can also reference params the standard way.