8

When I use Gonzalos Medinas' method in the link everything turns out fine except that my circles seems to be off by about 0.05 in the x-direction.

This is his code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\draw (0,-1)--(10,-1);
\node[mark size=3pt,color=red] at (0,-1) {\pgfuseplotmark{*}};
\node[mark size=5pt,color=blue] at (5cm,-1) {\pgfuseplotmark{triangle*}};
\node[mark size=4pt,color=olive] at (10cm,-1) {\pgfuseplotmark{square*}};

\draw[mark=*,mark size=3pt,mark options={color=olive}] plot coordinates {(0,-2)} 
  -- plot[mark=triangle*,mark options={color=blue}] coordinates {(5cm,-2)} 
  -- plot[mark=square*,mark size=4pt,mark options={color=red}] coordinates {(10cm,-2)};
\end{tikzpicture}

\end{document}

I use just a part of his code in another one of my plots: a slight modification (for changes see below)

\node[mark size=3pt,color=red] at (0,-1) {\pgfuseplotmark{*}};
\node[mark size=5pt,color=blue] at (2,-1) {\pgfuseplotmark{triangle*}};
\node[mark size=4pt,color=olive] at (1,-1) {\pgfuseplotmark{square*}};

He uses (e.g.)

\node[mark size=4pt,color=olive] at (10cm,-1) {\pgfuseplotmark{square*}};

while I use (no squares!)

\node[mark size=4pt,color=olive] at (1,-1) {\pgfuseplotmark{*}};

What is wrong here?

0

1 Answer 1

11

New answer

Paul Gaborit points out that the pgfmanual specifically mentions that pgf commands such as \pgfuseplotmark should not be used in situation, such as a node, where text is expected. Rather they should be in a pgfpicture (or tikzpicture) environment.

One (ugly) work around to your approach is then to write the node argument in pgfpicture environment:

Ugly test

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\draw (-1,0) -- ++(2,0);
\draw (0,-1) -- ++(0,2);
\node[mark size=5pt,color=blue,draw] at (0,0) {%
\begin{pgfpicture}
  \pgfuseplotmark{triangle*}
\end{pgfpicture}%
};

\end{tikzpicture}

\end{document}

I have drawn a rectangle around the node to show the spacing, compare with bad spacing demonstrated in the original answer below.

Better is to use the mark mechanism as intend in a plot of just one point:

Second test

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
  \draw (-1,0) -- ++(2,0);
  \draw (0,-1) -- ++(0,2);
  \draw[color=blue] plot[mark=triangle*,mark size=5pt] (0,0);
\end{tikzpicture}

\end{document}

In your code this would give

Sample full output

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\draw (0,0) -- ++(0,-3);
\draw (5cm,0) -- ++(0,-3);
\draw (10cm,0) -- ++(0,-3);

\draw (0,-1)--(10,-1);
\draw[color=red] plot[mark=*,mark size=3pt] (0,-1);
\draw[color=blue] plot[mark=triangle*,mark size=5pt] (5cm,-1);
\draw[color=olive] plot[mark=square*,mark size=4pt] (10cm,-1);

\draw[mark=*,mark size=3pt,mark options={color=olive}] plot coordinates {(0,-2)} 
  -- plot[mark=triangle*,mark options={color=blue}] coordinates {(5cm,-2)} 
  -- plot[mark=square*,mark size=4pt,mark options={color=red}] coordinates {(10cm,-2)};
\end{tikzpicture}

\end{document}

Original answer

Most of the plot mark definitions have an error in them with newlines not commented out. For example the triangle* is defined as:

\pgfdeclareplotmark{triangle*}
{%
  \pgfpathmoveto{\pgfqpoint{0pt}{\pgfplotmarksize}}
  \pgfpathlineto{\pgfqpointpolar{-30}{\pgfplotmarksize}}
  \pgfpathlineto{\pgfqpointpolar{-150}{\pgfplotmarksize}}
  \pgfpathclose
  \pgfusepathqfillstroke
}

Lines 3, 4 and 5 do not have the newline escaped and so insert a space in to the output, as you can see by drawing the box around the node:

Sample error

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\draw (0,0) -- ++(0,-2);

\node[mark size=5pt,color=blue,draw] at (0,-1) {\pgfuseplotmark{triangle*}};

\end{tikzpicture}

\end{document}

Correcting these definitions, mostly found in pgflibraryplotmarks.code.tex gives in the original example:

Sample output

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
\pgfdeclareplotmark{triangle*}
{%
  \pgfpathmoveto{\pgfqpoint{0pt}{\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpointpolar{-30}{\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpointpolar{-150}{\pgfplotmarksize}}%
  \pgfpathclose
  \pgfusepathqfillstroke
}
\pgfdeclareplotmark{*}
{%
  \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}%
  \pgfusepathqfillstroke
}

\draw (0,0) -- ++(0,-3);
\draw (5cm,0) -- ++(0,-3);
\draw (10cm,0) -- ++(0,-3);

\draw (0,-1)--(10,-1);
\node[mark size=3pt,color=red] at (0,-1) {\pgfuseplotmark{*}};
\node[mark size=5pt,color=blue] at (5cm,-1) {\pgfuseplotmark{triangle*}};
\node[mark size=4pt,color=olive] at (10cm,-1) {\pgfuseplotmark{square*}};

\draw[mark=*,mark size=3pt,mark options={color=olive}] plot
  coordinates {(0,-2)} 
  -- plot[mark=triangle*,mark options={color=blue}] coordinates {(5cm,-2)} 
  -- plot[mark=square*,mark size=4pt,mark options={color=red}]
  coordinates {(10cm,-2)}; 
\end{tikzpicture}

\end{document}

I have added vertical lines to show the alignment.

3
  • The \pgfuseplotmark command should not be used as text! "Most, but not all, commands of the pgf package must be given within a {pgfpicture} environment." (pgf manual, v3.0, p.973) Commented Sep 24, 2014 at 21:02
  • @PaulGaborit Many thanks for pointing this out. I have added a new approach. Commented Sep 25, 2014 at 10:04
  • You can still use the pgf command if you select \nullfont. That warning Paul is mentioning is for pure commands without any environment around them i.e. PDF literals without any controlling TikZ or PGF picture around them. For example, \node[mark size=5pt,color=blue,draw] at (0,-1) {\nullfont\pgfuseplotmark{triangle*}}; should work.
    – percusse
    Commented Sep 25, 2014 at 10:17

You must log in to answer this question.

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