0

In the MWE below, why do not have arrows in my plot?

\documentclass[12pt, border=1pc]{standalone}
\RequirePackage{tikz}
\RequirePackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture} \begin{axis}[axis x line=middle, axis y line=middle,, xtick={1.0, 3.0}, ytick={1.0, 3.0}, samples=100, xmin=-1,xmax=4.5, ymin=-1,ymax=4.5]

\addplot[domain={-1:4}]{x}; \addplot[domain={-1:4}, postaction={decorate, decoration={markings, mark=at position 2 with {\arrow[thick]{>}}, mark=at position 3 with {\arrowreversed[thick]{>}}} } ]{((x-3)^2 * (x-1)^2) + x}; \end{axis} \end{tikzpicture}

\end{document}

enter image description here

blackened
  • 4,181

1 Answers1

1

Your range limits on Y combined with your marks positions are truncating the arrow.

I debugged it by commenting anything that is not necessary to have arrows to the plot.

    \begin{tikzpicture}
        \begin{axis}[axis x line=middle,
%           axis y line=middle,
%           xtick={1.0, 3.0},
%           ytick={1.0, 3.0},
%           samples=100,
%           xmin=-1,xmax=4.5,
%           ymin=-1,ymax=4.5,
            ]

% \addplot[domain={-1:4}]{x}; \addplot[domain={-1:4}, postaction={decorate, decoration={ markings, mark=at position 0.65 with {\arrow{>};} }} ]{((x-3)^2 * (x-1)^2) + x}; \end{axis} \end{tikzpicture}

enter image description here

The arrow is exactly where I thought it would be 65% of the plotted curve.

By playing a bit with the code:

    \begin{tikzpicture}
        \begin{axis}[
%           axis x line=middle,
%           axis y line=middle,
%           xtick={1, 3.0},
%           ytick={1.0, 3.0},
            samples=100,
            xmin=-1,xmax=4,
            ymin=-1,ymax=4.5,
            ]                   
%           \addplot[domain={-1:4}]{x};
            \addplot[domain={-1:4.5},
            postaction={decorate, decoration={
                markings,
                mark=at position 0.65 with {\arrow{>};}
            }}
            ]{((x-3)^2 * (x-1)^2) + x};
        \end{axis}
    \end{tikzpicture} 

enter image description here

anis
  • 1,510
  • 5
  • 13
  • Thank you. I do not understand this truncating business. In my example, for example, I npow did .85 and it worked, I see the arrow. I did .7, .75, .9, and I see no arrow. I am confused. – blackened Jan 29 '24 at 14:59
  • My understanding is that the addplot command is executed before the axisenvironment limits the plot. So the curve is plotted. Then the arrow is positioned at x%. Then x or y limit truncates it. – anis Jan 29 '24 at 15:01
  • Thank you. Is there an alternative approach? – blackened Jan 29 '24 at 15:06
  • https://tikz.dev/pgfplots/reference-specifyrange#autosec-5859. Check this option: update limits=true|false (initially true). – anis Jan 29 '24 at 15:09
  • or changing the plotting tool to https://tikz.dev/dv-introduction – anis Jan 29 '24 at 15:30