【问题标题】:TikZ: plotting data file with missing valuesTikZ:绘制缺少值的数据文件
【发布时间】:2017-08-21 18:27:52
【问题描述】:

我有这些数据:

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

这是我得到的图表:

非常感谢!

顺便说一句。在真实数据中,一个数据集在数据中间缺少 x/y 值。我希望这与我的示例相比无关紧要。

【问题讨论】:

    标签: latex tikz pgf


    【解决方案1】:

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

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

    解决方案 1. 您可以将空单元格替换为 NaNpgfplots 会正确解释:

    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 文件中,但它也应该与单独的数据文件一起使用。


    【讨论】:

      猜你喜欢
      • 2019-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2011-04-04
      • 1970-01-01
      相关资源
      最近更新 更多