3

There is a problem when I try to draw something over an already done graph, like a parabola: enter image description here

\begin{tikzpicture}
 \begin{axis}
  \addplot[red, ultra thick] (x*x,x);
   \end{axis}
\end{tikzpicture}

Let's assume there is another constant at x=-3, so we would would expecte a vertical segment along the x value. Instead we get:

\begin{tikzpicture}
 \begin{axis}
  \addplot[red, ultra thick] (x*x,x);
  \draw[dashed,color=blue] (-3,-10) -- (-3,10);
   \end{axis}
\end{tikzpicture} 

enter image description here

and all that is done is the thin blue segment. I was expecting something more notable. Aren't all elements of tikzpicture supposed to be done in the same scale or using the same coordinate system?

1 Answer 1

4

Your intuition about the coordinate system is correct. You have to prefix the coordinates by axis cs:.

\draw[dashed,color=blue] (axis cs:0,-4) -- (axis cs:25,2);

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
 \begin{axis}
  \addplot[red, ultra thick] (x*x,x);
  \draw[dashed,color=blue] (axis cs:0,-4) -- (axis cs:25,2);
 \end{axis}
\end{tikzpicture}
\end{document}
1
  • 4
    This is actually only needed if you run pgfplots in the backwards compatibility mode or if you use a very old version (earlier than 1.11, we are now at 1.17), neither of which is recommended. The cleaner way is to use \pgfplotsset{compat=1.17}.
    – user230294
    Dec 11, 2020 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .