12

I am using pgfplots to create simple theoretical graphs, so I use middle axis line style. What bothers me is that

  • x axis label is above instead of below or right of x axis and
  • y axis label is right instead of left or above of y axis.

I have extensively studied pgfplots manual (I find it much more complex and disordered than tikz manual) and tried things to regulate this myself using stuff like every axis x label/.style={at={(current axis.right)},anchor=north west}, but to no avail. How can I solve this problem?

\documentclass{scrartcl}
\usepackage{pgfplots}

\begin{document}

\pgfplotsset{standard/.style={axis x line=middle,axis y line=middle,enlarge x limits=0.15,enlarge y limits=0.15}}

\begin{tikzpicture}
\begin{axis}[standard,xlabel=$t$,ylabel=$v$,xtick={0,1.7},xticklabels={0,$t_1$},ytick={0,21},yticklabels={0,$v_0$}]
\addplot[thick,color=black] coordinates { (0,21) (1.7,21) (8.7,0) };
\end{axis} 
\end{tikzpicture}

\end{document}
2
  • 1
    @Jake I've rephrased. IMHO pgfplots is fine package, so it would "deserve" better structured and clearer manual.
    – Pygmalion
    Aug 23 '12 at 11:16
  • 1
    I still don't really see the point of putting that sentence into the question. It adds no value to the question, and it's unlikely to lead to better documentation for PGFplots. I think the constructive thing to do would be to remove the sentence and instead write an email to the PGFplots author Christian Feuersaenger, explaining what you think could be done to improve the documentation.
    – Jake
    Aug 23 '12 at 11:55
25

You almost had it: The axis anchors you're looking for are called current axis.right of origin and current axis.above origin. The anchors are shown on the very simple and clear diagrams on pages 314-315 of the manual.

\documentclass{scrartcl}
\usepackage{pgfplots}

\begin{document}

\pgfplotsset{
    standard/.style={
        axis x line=middle,
        axis y line=middle,
        enlarge x limits=0.15,
        enlarge y limits=0.15,
        every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
        every axis y label/.style={at={(current axis.above origin)},anchor=north east}
    }
}

\begin{tikzpicture}
\begin{axis}[
    standard,
    xlabel=$t$,
    ylabel=$v$,
    xtick={0,1.7},
    xticklabels={0,$t_1$},
    ytick={0,21},
    yticklabels={0,$v_0$}
]
\addplot[thick,color=black] coordinates { (0,21) (1.7,21) (8.7,0) };
\end{axis} 
\end{tikzpicture}

\end{document}
1
  • Indeed. Believe or not I spent at least 1/2 hour searching and listing manual and did not find that page.
    – Pygmalion
    Aug 23 '12 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.