1

Latex and Tikz are going to get the life out of me...

I saw Need to do some changes to pgfplots axis #39099, and that example was working fine for me; so I modified it a bit, and came up with the following MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[hmargin=3cm,vmargin=2cm]{geometry}
\usepackage{floatrow}
\usepackage{tikz}
\usepackage{pgfplots}
% \usepackage{lua-visual-debug}

\begin{document}
\begin{figure}[H]%[h!tbp]
\centering
\begin{tikzpicture}
\begin{scope}
  \begin{axis}[
    clip=true,
    axis x line=middle,
    axis y line=middle,
    xmin = 2.5e-3,
    xmax = 4.2e-3,
    ymin = 0,
    ymax = 710,
    xlabel={},%{$t$\,[ms]},
    xlabel style={at={(axis description cs:1.01,+0.0)},anchor=west},
    ylabel={}, %{$U$\,[V]},
    ylabel style={at={(axis description cs:-0.02,1.01)},anchor=south},
    xtick=data,
    scaled x ticks=base 10:3,
    xtick scale label code/.code={}, % this to not show extra scale label
    x tick label style={
      rotate=-45,
      anchor=west,
      /pgf/number format/fixed,
      /pgf/number format/fixed zerofill,
      /pgf/number format/precision=3,
    },
    tick label style={font=\small,},
    legend cell align=left,
    legend pos=outer north east,
    % this for "the 0 is missing from the labels";
    after end axis/.code={
      \path (axis cs:0,0)
        node [anchor=north west,yshift=-0.075cm,xshift=-0.4em] {0}
        node [anchor=east,xshift=-0.075cm] {0};
    }
  ]
\addplot[mark=*] coordinates {(2.9e-3,400)};
\end{axis}
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}

Why is it then, that this MWE results with this:

test01a.png

... that is, the 0,0 stick to left of the margin, plot itself is to the right, overflowing the margin - all that while \centering being issued?

And if you comment out the after end axis/.code={...} part - then everything works as expected?!

What am I missing here?

sdaau
  • 17,079

1 Answers1

1

Meh... as it usually goes, as soon as I posted the question, I noticed that \path (axis cs:0,0), and I thought: "what would happen if I type rel" in there?" - and indeed, that fixes it; simply replace \path (axis cs:0,0) with:

\path (rel axis cs:0,0)

... in the code above, and the plot will center as expected...

It's still a brute force solution without any understanding of what went wrong - so if someone more knowledgeable would like to expand on that, they are more than welcome...

sdaau
  • 17,079
  • The difference is that axis cs really tries to go to the literally zero data value, rel axis cs instead assumes that the visible plot is parametrized with a number between 0 and 1. – percusse Jul 05 '14 at 10:19