pgf scatter 没有分配类别样式

pgf scatter 没有分配类别样式

我正在尝试使用该包生成散点图。但是,我在使用和选项pgfplots时遇到了麻烦。出于某种原因,LaTeX 不断向我发送以下错误:scatter/classesscatter src

软件包 pgfplots 警告:散点图/类别:找不到类别

最后,LaTeX 生成图表,但它没有为坐标分配任何样式: 在此处输入图片描述

这是我的代码的一个最小示例:

\documentclass[border = 1cm]{standalone}

\usepackage{tikz} % https://www.ctan.org/pkg/pgf
\usepackage{pgfplots} % https://www.ctan.org/pkg/pgfplots
   % -> 
   \pgfplotsset{compat = newest} 
   \usetikzlibrary{plotmarks}

\begin{filecontents}{data.dat}
c1  c2  c3
1   1   a
2   4   b
7   2   c
\end{filecontents}

\begin{document}

\begin{tikzpicture}
   \begin{axis}[
      scatter/classes = {
         a = {mark = *, draw = green},
         b = {mark = *, draw = blue},
         c = {mark = *, draw = red}
       }]
      \addplot[                 
         scatter,
         only marks,
         scatter src = explicit symbolic] 
      table[
         x = c1, 
         y = c2,
         meta = c3,
         col sep = space
      ]{data.dat};
   \end{axis}
\end{tikzpicture}

\end{document}

答案1

您只需替换a和之间的空格=,对b和 也类似c。否则类名将包含这些空格。

\documentclass[border = 1cm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
c1;c2;c3
1;1;a
2;4;b
7;2;c
\end{filecontents*}


\usepackage{tikz} % https://www.ctan.org/pkg/pgf
\usepackage{pgfplots} % https://www.ctan.org/pkg/pgfplots
   % -> 
   \pgfplotsset{compat = newest} 
   \usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
   \begin{axis}[
      scatter/classes = {
         a={mark = *, draw = green},
         b={mark = *, draw = blue},
         c={mark = *, draw = red}
       }]
      \addplot[                 
         scatter,
         only marks,
         scatter src=explicit symbolic] 
      table[
         x = c1, 
         y = c2,
         meta = c3,
         col sep = semicolon
      ]{data.csv};
   \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

现在标记具有相应颜色的(几乎看不见的)光晕,如果您希望它们也填充这些颜色,请使用

\documentclass[border = 1cm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
c1;c2;c3
1;1;a
2;4;b
7;2;c
\end{filecontents*}


\usepackage{tikz} % https://www.ctan.org/pkg/pgf
\usepackage{pgfplots} % https://www.ctan.org/pkg/pgfplots
   % -> 
   \pgfplotsset{compat = newest} 
   \usetikzlibrary{plotmarks}

\begin{document}

\begin{tikzpicture}
   \begin{axis}[
      scatter/classes = {
         a={mark = *, green},
         b={mark = *, blue},
         c={mark = *, red}
       }]
      \addplot[                 
         scatter,
         only marks,
         scatter src=explicit symbolic] 
      table[
         x = c1, 
         y = c2,
         meta = c3,
         col sep = semicolon
      ]{data.csv};
   \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容