2

I recently learned about the possibility to create custom plot marks using the \pgfdeclareplotmark option. However, from browsing the manual, the usage is not entirely clear to me.

I would like to have a marker style for crossed-out circles. Here's what I came up with:

\pgfdeclareplotmark{xo}{%
  \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}%
  \pgfpathmoveto{\pgfqpoint{-1.2\pgfplotmarksize}{-1.2\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpoint{1.2\pgfplotmarksize}{1.2\pgfplotmarksize}}%
  \pgfpathmoveto{\pgfqpoint{-1.2\pgfplotmarksize}{1.2\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpoint{1.2\pgfplotmarksize}{-1.2\pgfplotmarksize}}%
  \pgfusepathqstroke
}

This already works nicely, but I'd like to customize this a bit more:

  • I want the cross-mark to have a color different from the circle, preferably such that it can be given as an argument.
  • It would be nice to have the lines of the cross to be drawn a bit more squiggly, possibly akin to the cross mark (\ding{55}).

Here's an MWE, showing what my current attempt looks like (and how the cross-mark would ideally look like).

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pifont}
\newcommand{\xmark}{\ding{55}}%
\begin{document}
\pgfdeclareplotmark{xo}{%
  \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}%
  \pgfpathmoveto{\pgfqpoint{-1.2\pgfplotmarksize}{-1.2\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpoint{1.2\pgfplotmarksize}{1.2\pgfplotmarksize}}%
  \pgfpathmoveto{\pgfqpoint{-1.2\pgfplotmarksize}{1.2\pgfplotmarksize}}%
  \pgfpathlineto{\pgfqpoint{1.2\pgfplotmarksize}{-1.2\pgfplotmarksize}}%
  \pgfusepathqstroke
}
\begin{tikzpicture}
    \begin{axis}[xlabel=$x$,ylabel=$y$]
      \addplot[smooth,mark=xo,black] plot coordinates {
        (0,2)
        (2,3)
        (3,1)
      };
      \node[anchor=west] at (0.2,0.5) {Can you make it look like an \textcolor{red}\xmark{}?};
    \end{axis}
\end{tikzpicture}
\end{document}

MWE

  • Put the new X on top of the existing via \pgfnode ? – percusse Sep 25 '16 at 9:59
  • 1
    How can I make sure that the X is always nicely centered about the circle and scales correctly if I use a larger marker size? – carsten Sep 25 '16 at 10:00
2

With the help of Inkscape and the glorious svg2tikz extension (as well as converting back and forth the image a couple of times), I was able to come up with a solution:

\pgfdeclareplotmark{xo}{%
  \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}%
  \pgfusepathqstroke
  \path[draw=none,fill=red] (-1.2410\pgfplotmarksize,-1.6636\pgfplotmarksize) .. controls (-1.3125\pgfplotmarksize,-1.5121\pgfplotmarksize) and
  (-1.3142\pgfplotmarksize,-1.3244\pgfplotmarksize) .. (-1.2170\pgfplotmarksize,-1.1831\pgfplotmarksize) .. controls (-0.9789\pgfplotmarksize,-0.7541\pgfplotmarksize) and
  (-0.6560\pgfplotmarksize,-0.3820\pgfplotmarksize) .. (-0.3522\pgfplotmarksize,0.0007\pgfplotmarksize) .. controls (-0.4597\pgfplotmarksize,0.3080\pgfplotmarksize) and
  (-0.5793\pgfplotmarksize,0.6114\pgfplotmarksize) .. (-0.6749\pgfplotmarksize,0.9226\pgfplotmarksize) .. controls (-0.7289\pgfplotmarksize,1.0582\pgfplotmarksize) and
  (-0.5838\pgfplotmarksize,1.1276\pgfplotmarksize) .. (-0.4725\pgfplotmarksize,1.0881\pgfplotmarksize) .. controls (-0.4126\pgfplotmarksize,1.1418\pgfplotmarksize) and
  (-0.3420\pgfplotmarksize,1.1794\pgfplotmarksize) .. (-0.3118\pgfplotmarksize,1.0737\pgfplotmarksize) .. controls (-0.1920\pgfplotmarksize,0.8813\pgfplotmarksize) and
  (-0.1153\pgfplotmarksize,0.6618\pgfplotmarksize) .. (0.0194\pgfplotmarksize,0.4801\pgfplotmarksize) .. controls (0.2491\pgfplotmarksize,0.7120\pgfplotmarksize) and
  (0.4404\pgfplotmarksize,0.9798\pgfplotmarksize) .. (0.6716\pgfplotmarksize,1.2102\pgfplotmarksize) .. controls (0.7601\pgfplotmarksize,1.2826\pgfplotmarksize) and
  (0.8675\pgfplotmarksize,1.1351\pgfplotmarksize) .. (0.9475\pgfplotmarksize,1.2444\pgfplotmarksize) .. controls (1.1035\pgfplotmarksize,1.1629\pgfplotmarksize) and
  (1.0140\pgfplotmarksize,1.0177\pgfplotmarksize) .. (0.9191\pgfplotmarksize,0.9279\pgfplotmarksize) .. controls (0.6837\pgfplotmarksize,0.6417\pgfplotmarksize) and
  (0.4642\pgfplotmarksize,0.3430\pgfplotmarksize) .. (0.2408\pgfplotmarksize,0.0475\pgfplotmarksize) .. controls (0.3855\pgfplotmarksize,-0.2598\pgfplotmarksize) and
  (0.5445\pgfplotmarksize,-0.5609\pgfplotmarksize) .. (0.6685\pgfplotmarksize,-0.8774\pgfplotmarksize) .. controls (0.6706\pgfplotmarksize,-0.9845\pgfplotmarksize) and
  (0.5386\pgfplotmarksize,-1.0399\pgfplotmarksize) .. (0.5409\pgfplotmarksize,-1.1513\pgfplotmarksize) .. controls (0.4364\pgfplotmarksize,-1.3325\pgfplotmarksize) and
  (0.3201\pgfplotmarksize,-1.0970\pgfplotmarksize) .. (0.2551\pgfplotmarksize,-1.0079\pgfplotmarksize) .. controls (0.1347\pgfplotmarksize,-0.8324\pgfplotmarksize) and
  (0.0259\pgfplotmarksize,-0.6485\pgfplotmarksize) .. (-0.0985\pgfplotmarksize,-0.4762\pgfplotmarksize) .. controls (-0.2106\pgfplotmarksize,-0.5277\pgfplotmarksize) and
  (-0.2609\pgfplotmarksize,-0.6763\pgfplotmarksize) .. (-0.3397\pgfplotmarksize,-0.7730\pgfplotmarksize) .. controls (-0.5313\pgfplotmarksize,-1.0592\pgfplotmarksize) and
  (-0.7140\pgfplotmarksize,-1.3513\pgfplotmarksize) .. (-0.8980\pgfplotmarksize,-1.6422\pgfplotmarksize) .. controls (-0.9557\pgfplotmarksize,-1.7528\pgfplotmarksize) and
  (-1.1546\pgfplotmarksize,-1.8080\pgfplotmarksize) .. (-1.2271\pgfplotmarksize,-1.6880\pgfplotmarksize) -- (-1.2410\pgfplotmarksize,-1.6636\pgfplotmarksize) --
  (-1.2410\pgfplotmarksize,-1.6636\pgfplotmarksize) -- cycle;
}

enter image description here

1

Skipping all the conversion magic, the pgfnode version suggested by percusse of course also works:

\pgfdeclareplotmark{xo}{%
  \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}%
  \pgfusepathqstroke
  \pgfnode{rectangle}{center}{\resizebox{2.5\pgfplotmarksize}{2.5\pgfplotmarksize}{\color{red}\ding{55}}}{}{}
}

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.