1

我有这个数据:

价值观

data2 缺少第三点。所以我想,我会定义两个不同的 x 列并将 data2 分配给 x2。

问题:data1 的第三个点在编译图形中上升到 3。如果我有不同的和更多的值,点开始去任何地方,但不是它们所属的地方。

那是我使用的代码:

\addplot[only marks, mark = diamond, color = orange, mark size = 3pt]
 table[x=x1, y=data1]{example.dat};
\addlegendentry{data1};

\addplot[only marks, mark = square, color = gray, mark size = 3pt]
 table[x=x2, y=data2]{example.dat};
\addlegendentry{data2};

\addplot[only marks, mark = o, color = blue, mark size = 3pt]
 table[x=x1, y=data3]{example.dat};
\addlegendentry{data3};

这是我得到的图表:

图形

非常感谢!

顺便提一句。在真实数据中,一个数据集在数据中间缺少 ax/y 值。我希望与我的示例相比,这并不重要。

4

1 回答 1

1

pgfplots将 2 个制表符解释为单个分隔符。因此,它将数据文件视为:

x1  x2  data1   data2   data3
0   0   1   2   3
1   1   1   2   3
2   1   3

解决方案 1.您可以用NaN替换空单元格。pgfplots将正确解释这一点:

x1  x2  data1   data2   data3
0   0   1   2   3
1   1   1   2   3
2   nan 1   nan 3

解决方案 2.使用另一种分隔符(例如,分号或逗号):

\begin{filecontents*}{example.csv}
x1;x2;data1;data2;data3
0;0;1;2;3
1;1;1;2;3
2;;1;;3
\end{filecontents*}
\pgfplotstableread[col sep = semicolon]{example.csv}\mydata

\begin{document}
...

在这里,我将数据文件包含在 TeX 文件中,但它也应该与单独的数据文件一起使用。


在此处输入图像描述

于 2017-08-22T08:55:23.980 回答