3

I am trying to draw a double headed arrow as a plot in pgfplots but the arrow does not seem to be rendering right. Below a minimal example of an attempt to draw a double sided arrow with pgfplots (red line), as can be seen in the plot the leftmost arrow is pointing the wrong way.

\documentclass{standalone}
\usepackage{comment}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}
\begin{axis}[xmax = 10, ymax = 10, legend pos = south east] 
    \addplot [<->, red, thick] (0,0) to (9,9);
    \draw[<->, blue, thick] (0,1) to (8, 9);

    \addlegendentry{plot}
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Can anyone provide any insights on how I can solve this issue?

3
  • 2
    Why do you want to use pgfplots when to do this TikZ is enough?
    – AndréC
    Aug 15, 2019 at 10:18
  • 1
    @AndréC perhaps just the principal of it? I'd say it is a legitimate question. It you can reduce it to <- (which presumably is the part being used in <->). Using pgfplots is often a fast too to get the axis even if the plot is just done by hand.
    – daleif
    Aug 15, 2019 at 10:36
  • 1
    \addplot [<->, red, thick,domain=0:9] {x};
    – user31034
    Aug 15, 2019 at 10:59

1 Answer 1

3

You have wrong defined addplot. Try:

\documentclass{standalone}
%\usepackage{comment}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
%\usetikzlibrary{patterns}
%\usepgfplotslibrary{fillbetween}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[xmax = 10, ymax = 10, legend pos = south east]
    \addplot [<->, red, thick] coordinates {(0,0)  (9,9)}; % <----
    \draw[<->, blue, thick] (0,1) to (8, 9);
    \addlegendentry{plot}
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

Edit: Macro \addplot is designed for drawing function (on given domain with defined number of sampling points), drawing lines between number of coordinates collected in table or in coordinates(as it is done in above MWE). Functions can draw with use of the Bezier curves or only draw their coordinates with different marks, etc. It not support drawing lines between two coordinates using to, edge or -- as it is at "ordinary" path (draw) commands.

The details should be described in the pgfplots manual. For further question about syntax please address them to package author (with new question).

4
  • 2
    any explanation as to why the other syntax would not work?
    – daleif
    Aug 15, 2019 at 11:09
  • 2
    @daleif The other syntax does not seem to match the required syntax \addplot[⟨options⟩] ⟨input data⟩ ⟨trailing path commands⟩; as described on page 43 of the pgfplots manual. So maybe a better question is, why did it not result in an error, but mangled output instead? Aug 15, 2019 at 11:43
  • @HaraldHanche-Olsen I think you're right, I cannot find any information as to ` to ` being a supported syntax for \addplot, but since \addplot ends up as a \path (I assume), the result is valid for \path, that might explain the missing error msg, but not quite the strange output.
    – daleif
    Aug 15, 2019 at 12:05
  • Thanks for the answer. I didn't realise that the syntax was not valid.
    – KillaKem
    Aug 15, 2019 at 14:18

You must log in to answer this question.

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