控制 pgfplots 中数据点后面彩色圆圈的大小

控制 pgfplots 中数据点后面彩色圆圈的大小

此代码基于斯蒂芬·平诺成立这里

我想控制放置在数据点后面的彩色圆圈的大小。当前的圆圈太大,我想知道如何减小它的大小。

以下是斯蒂芬

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        fit,
        shapes,
        pgfplots.groupplots,
    }
        \newcommand{\dsnfive}{prob5_2.dat}
    \begin{filecontents*}{\dsnfive}
        2   7   4   8
        3   6   5   8
        2   5   9   5
        3   5   9   9
        3   3   9   4
        2   2   8   9
        5   1   8   8
        6   2   6   9
        8   1   7   4
        6   4   4   4
    \end{filecontents*}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xmin=1,
            xmax=10,
            ymin=0,
            ymax=10,
            legend pos=outer north east,    % <-- used predefined command to position legend
            only marks,
            mark=*,
            mark options={
                scale=1.2,
            },
        ]
                % store number of data points
                \pgfplotstablegetrowsof{\dsnfive}
                \pgfmathtruncatemacro{\N}{\pgfplotsretval-1}

            \addplot+ [
                blue,
                % -------------------------------------------------------------
                % comment this block to hide names of the coords
                % -----
                % text of node coords should be the same as for the
                % corresponding coordinates
                nodes near coords=a\coordindex,
                % increase the distance of the nodes a bit
                nodes near coords align={above=1ex},
                % -------------------------------------------------------------
            ] table [x index=0,y index=1] {\dsnfive}
                % set a coordinate on each data point
                % (needed for the `fit' library solution)
                \foreach \i in {0,...,\N} {
                    coordinate [pos=\i/\N] (a\i)
                }
            ;
                \addlegendentry{$class 1$}
            \addplot+ [
                red,
                % -------------------------------------------------------------
                nodes near coords=b\coordindex,
                nodes near coords align={below=1ex},
                % -------------------------------------------------------------
            ] table [x index=2,y index=3] {\dsnfive}
                % set a coordinate on each data point
                % (needed for the `fit' library solution)
                \foreach \i in {0,...,\N} {
                    coordinate [pos=\i/\N] (b\i)
                }
            ;
                \addlegendentry{$class 2$}
                \addplot[]coordinates{(2,7)}node[pos=0](A){};
               \node[very thick, draw=green!75!black,circle,fit=(A), fill = red, opacity = 0.2]{};
\end{axis}
            % now add the circles to the points
            \foreach \i in {a0,b6,b8} {
                \draw [green!60!black,thick] (\i) circle (5pt);
            }
    \end{tikzpicture}
\end{document}

答案1

大圆圈的大部分空间是由inner sep边距(默认值为0.3333em)造成的——节点文本为空。因此,减少inner sep有助于:

\node[
  very thick,
  draw=green!75!black,
  circle,
  fit=(A),
  fill=red,
  opacity=0.2,
  inner sep=2pt,
]{};

结果

相关内容