[Tex/LaTex] Addplot doesn’t accept color

colorpgfplots

I tried to plot a sequence with pgfplots but I cannot set the color:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}

\begin{document}


\begin{tikzpicture}
  \pgfmathsetmacro{\Start}{1} %% start value
  \pgfmathsetmacro{\End}{5} %% end value
  \begin{axis}[mark options={mark=x},only marks,axis lines=center,xlabel=$n$,ylabel=$a_n$,samples at={\Start,...,\End},xtick={0,1,...,\End},grid=both, minor y tick num=4,enlargelimits]
    \addplot[green] coordinates {(0,0)};
    \addplot[green] {1/x};%
  \end{axis}
\end{tikzpicture}

\end{document}

What would be the proper way to specify the color here?

Best Answer

You have to use \addplot+ instead of \addplot. The \addplot version overwrites the default settings with the given options (here only green) and hence the plot is not drawn at all.On the other hand \addplot+ appends the options to the default ones.

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}


\begin{tikzpicture}
  \pgfmathsetmacro{\Start}{1} %% start value
  \pgfmathsetmacro{\End}{5} %% end value
  \begin{axis}[mark options={mark=x},only marks,axis lines=center,xlabel=$n$,ylabel=$a_n$,samples at={\Start,...,\End},xtick={0,1,...,\End},grid=both, minor y tick num=4,enlargelimits]
    \addplot+[green] coordinates {(0,0)};
    \addplot+[green] {1/x};%
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here