3

How can I modify the anchor of the marker (in this case a triangle) to be at the leftmost tip of the triangle?. Now, quite obviously the anchor is the center of the triangle.

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}

\begin{axis}[xmin=0, xmax=2.8,clip=false,
    ymin=0.0, ymax=0.3]


\addplot [mark=triangle*, mark size=2, mark options={solid,draw=black,fill=black}, only marks, every mark/.append style={rotate=90}]
table {%
0.0 0.0
};

\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

5

The easiest is probably to add xshift=\pgfplotmarksize+\pgflinewidth to the mark options.

Another method might be to define a new plotmark, like mytri in the code below.

Left, xshifted triangle* and right, mytri:

enter image description here

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfdeclareplotmark{mytri}
{%
  \pgfpathmoveto{\pgfqpoint{0pt}{-1\pgflinewidth}}%
  \pgfpathlineto{\pgfqpointpolar{-60}{2\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpointpolar{-120}{2\pgfplotmarksize}}%
  \pgfpathclose
  \pgfusepathqfillstroke
}


\begin{document}
\begin{tikzpicture}

\begin{axis}[xmin=0, xmax=2.8,clip=false,
    ymin=0.0, ymax=0.3,grid]

\addplot [mark=mytri,
          mark size=2,
          mark options={
              draw=black,
              fill=black
          },
          only marks,
          every mark/.append style={rotate=90}
]
table {%
1 0.1
};
\addplot [mark=triangle*,
          mark size=2,
          mark options={
              draw=black,
              fill=black,
              xshift=2.4pt % added
          },
          only marks,
          every mark/.append style={rotate=90}
]
table {%
0.5 0.1
};

\end{axis}

\end{tikzpicture}
\end{document}

A couple of other (not quite perfect) definitions. The default triangle* is plotted on top in red, with opacity=0.5, so the difference can be seen. I don't know how to make this independent of the mark size though.

enter image description here

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfdeclareplotmark{mytri}
{%
  \pgfpathmoveto{\pgfqpoint{0pt}{-\pgflinewidth}}%
  \pgfpathlineto{\pgfpointadd{\pgfqpointpolar{-60}{2\pgfplotmarksize}}{\pgfpoint{-0.5\pgflinewidth}{0pt}}}%
  \pgfpathlineto{\pgfpointadd{\pgfqpointpolar{-120}{2\pgfplotmarksize}}{\pgfpoint{0.5\pgflinewidth}{0pt}}}%
  \pgfpathclose
  \pgfusepathqfillstroke
}

\pgfdeclareplotmark{mytri2}
{%
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}%
  \pgfpathlineto{\pgfqpointpolar{-60}{2\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpointpolar{-120}{2\pgfplotmarksize}}%
  \pgfpathclose
  \pgfusepathqfill % only fill, no stroke
}


\begin{document}
\begin{tikzpicture}[
  % change this to change the mark size
  declare function={msize=2;}
]

\begin{axis}[
  width=2cm,height=1cm,
  scale only axis,
  xmin=0.45,xmax=0.65,
  ymin=0.0, ymax=0.2,
  xtick={0.5,0.6},
  xticklabels={},
  ytick=\empty,
  grid,
  clip=false
]


\addplot [mark=mytri,
          mark size=msize,
          mark options={
              draw=black,
              fill=black,
          },
          only marks,
          every mark/.append style={rotate=90},
          nodes near coords={\tiny mytri},
]
table {%
0.5 0.1
};
%
\addplot [mark=mytri2,
          mark size=msize,
          mark options={
              draw=black,
              fill=black,
          },
          only marks,
          every mark/.append style={rotate=90},
          nodes near coords={\tiny mytri2},
          nodes near coords align=below
]
table {%
0.6 0.1
};


\addplot [mark=triangle*,
          mark size=msize,
          mark options={
              draw=red,
              fill=red,
              xshift={msize+0.4pt},
              draw opacity=0.5 % to see difference with the other two 
          },
          only marks,
          every mark/.append style={rotate=90}
]
table {%
0.5 0.1
0.6 0.1
};

\end{axis}

\end{tikzpicture}
\end{document}
  • I see now the shape wasn't exactly the same, so the angles (-60 and -120) in the plotmark definition should be changed a bit. – Torbjørn T. May 9 '18 at 9:06
  • Thanks for the answer! Do you know what the right angles might be? – Pierpaolo May 9 '18 at 11:27
  • 1
    @Pierpaolo I'm unable to make it perfect. 60 and 120 are in a way correct, the problem comes from the path starting at \pgfqpoint{0pt}{-1\pgflinewidth}. I tried fixing that in the updated answer, but it's not perfect, and I don't know how to make it perfect. – Torbjørn T. May 9 '18 at 12:22
  • 1
    @Pierpaolo xshift=\pgfplotmarksize+\pgflinewidth might be the easiest method, saves you from guessing the shift. – Torbjørn T. May 9 '18 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.