tikzpictures inside pgfplots' axis
When having a tikzpicture inside pgfplots's axis environment strange
effects can be observed which I guess stem from the fact that the
corresponding coordinate systems are interfering with each other:
\begin{tikzpicture}
\begin{axis}[
xlabel={A \tikz\draw[->](0,0)--++(1em,0); B},
]
\addplot {x*x};
\end{axis}
\end{tikzpicture}
My first idea was to add pgfplots' option disabledatascaling which however
seems to make things worse:
\begin{tikzpicture}
\begin{axis}[
disabledatascaling,
xlabel={A \tikz\draw[->](0,0)--++(1em,0); B},
]
\addplot {x*x};
\end{axis}
\end{tikzpicture}
What actually does seem to work is adding explicit values for xmin, xmax,
ymin and ymax:
\begin{tikzpicture}
\begin{axis}[
xlabel={A \tikz\draw[->](0,0)--++(1em,0); B},
xmin = -6, xmax = 6,
ymin = 0, ymax = 25,
]
\addplot {x*x};
\end{axis}
\end{tikzpicture}
However, this still isn't ideal since it forces me to a) set those values
explicitly and b) looses the margin between plot and axes. So my question
is: is there a better way to deal with situations like this?
Of course this isn't a real world example but the inner tikzpicture may
actually be drawn by another command (and not look like an arrow at all).
Complete code:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={A \tikz\draw[->](0,0)--++(1em,0); B},
]
\addplot {x*x};
\end{axis}
\end{tikzpicture}
\bikskip
\begin{tikzpicture}
\begin{axis}[
disabledatascaling,
xlabel={A \tikz\draw[->](0,0)--++(1em,0); B},
]
\addplot {x*x};
\end{axis}
\end{tikzpicture}
\bikskip
\begin{tikzpicture}
\begin{axis}[
xlabel={A \tikz\draw[->](0,0)--++(1em,0); B},
xmin = -6, xmax = 6,
ymin = 0, ymax = 25,
]
\addplot {x*x};
\end{axis}
\end{tikzpicture}
\end{document}
No comments:
Post a Comment