3

I loathe the predefined arrow styles in tikzor pgfplots and managed to apply customized arrows in tikz by using a decoration. Now I tried to apply the same decoration code inside a pgfplots axis and it failed with cryptic error.

This answer I found: https://tex.stackexchange.com/a/51584/75284 is specifically about applying decorations to pgfplots axis lines, and it compiles for me, but inserting my \fill command for the arrow head I need and removing the \arrow command, the compilation just hangs:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows, decorations,decorations.markings}

\tikzset{ % this is the arrow style I want
    myarrow/.style={decoration={markings, mark=at position 1 with {
    \fill(-0.3,-0.05) -- (0,0) -- (-0.3,0.05) -- cycle;
    }}, postaction={decorate},shorten >=5 pt}
}


\makeatletter
\tikzset{
    nomorepostaction/.code=\makeatletter\let\tikz@postactions\pgfutil@empty, % From https://tex.stackexchange.com/questions/3184/applying-a-postaction-to-every-path-in-tikz/5354#5354
    my axis/.style={
        postaction={
            decoration={
                markings,
                mark=at position 1 with {
                \arrow[ultra thick]{latex} % this works
                %\fill(-0.3,-0.05) -- (0,0) -- (-0.3,0.05) -- cycle; % this is just the \fill command pasted in
                }
            },
            decorate,
            nomorepostaction
        },
        thin,
        -, % switch off other arrow tips
        every path/.append style=my axis % this is necessary so it works both with "axis lines=left" and "axis lines=middle"
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}

\begin{axis}[
    axis lines=middle,
    axis line style={my axis}
]
\addplot coordinates {(-0.1,-0.2) (1.2,1.2)};
\end{axis}
\draw[myarrow] (0,0) -- (3,5);
\end{tikzpicture}
\end{document}

screenshot

This is just my attempt, though. I would welcome any solutions on how to use fully customizeable arrow heads in pgfplots axis lines. E.g. if there is a way to place a \draw command arrow line at the right spots, it would work, too.

lblb
  • 3,454

1 Answers1

4

I solved my problem with arrows.meta, which I somehow missed completely the last few years.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}

\tikzset{
    myarrow/.style={-{Triangle[length=3mm,width=1mm]}}
}


\begin{document}
\begin{tikzpicture}

\begin{axis}[
    axis lines=middle,
    axis line style={myarrow}
]
\addplot coordinates {(-0.1,-0.2) (1.2,1.2)};
\end{axis}
\draw[myarrow] (0,0) -- (1,5.5);
\end{tikzpicture}
\end{document}

screenshot

lblb
  • 3,454