定制的 pgf 绘图标记

定制的 pgf 绘图标记

我最近了解到可以使用该\pgfdeclareplotmark选项创建自定义绘图标记。但是,通过浏览手册,我并不完全清楚如何使用。

我想要一种带有划线圆圈的标记样式。以下是我想到的:

\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
}

这已经运行得很好了,但我想对其进行更多的自定义:

  • 我希望十字标记的颜色与圆圈不同,最好是可以作为参数给出。
  • 如果十字架的线条能够画得更弯曲一些,就更好了,可能类似于十字标记(\ding{55})。

这是 MWE,展示了我当前的尝试是什么样子(以及十字标记理想的样子)。

\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}

平均能量损失

答案1

Inkscape在出色的扩展的帮助下svg2tikz(以及来回转换图像几次),我能够想出一个解决方案:

\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;
}

在此处输入图片描述

答案2

跳过所有转换魔法,pgfnode建议的版本敲击当然也有效:

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

相关内容