pgfplots 无法从 CSV 绘图

pgfplots 无法从 CSV 绘图

我有一个名为“dat.csv”的文件,其中包含以下格式的数据:

x,y,z
-2.4,-2.4,0.00208966369454526
-2.3,-2.4,0.00245568047497186
-2.2,-2.4,0.00284901821144199
-2.1,-2.4,0.00326424484110634
-2,-2.4,0.00369478959101684
-1.9,-2.4,0.00413324571684902
-1.8,-2.4,0.00457174861531703
-1.7,-2.4,0.00500239752919971
-1.6,-2.4,0.00541768332000374
-1.5,-2.4,0.005810883691126
-1.4,-2.4,0.00617639102950998
-1.3,-2.4,0.00650994613105532
-1.2,-2.4,0.0068087622314587
-1.1,-2.4,0.00707153627611177
-1,-2.4,0.00729835639420583
-0.9,-2.4,0.00749052445419115
-0.8,-2.4,0.00765031919830823
-0.7,-2.4,0.00778072823782364
-0.6,-2.4,0.0078851762449041
-0.5,-2.4,0.00796727266169779
-0.4,-2.4,0.00803059618622074
-0.3,-2.4,0.00807852634842078
-0.2,-2.4,0.00811412573961708
-0.0999999999999996,-2.4,0.00814007074426613
4.44089209850063e-16,-2.4,0.00815862445567777
...

我想使用 pgfplots 绘制生成此数据的函数。到目前为止,我已经:

\documentclass{scrartcl}

\usepackage{pgfplots}
 \pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot3[surf]
    table{dat.csv};
  \end{axis}
\end{tikzpicture}
\end{document}

然而,这并不起作用,因为我得到:

! Package pgfplots Error: Sorry, the requested column number '1' in table 'dat.
csv' does not exist!? Please verify you used the correct index 0 <= i < N..

对于列号 1 和 2 以及以下类型的错误:

! Package PGF Math Error: Could not parse input '-2.4,-2.4,0.00208966369454526' as a floating point number, sorry. The unreadable part was near ',-2.4,0.00208966369454526'..

任何帮助,将不胜感激!

答案1

您必须使用\addplot3[surf] table [col sep=comma] {dat.csv};来告诉 PGFPlots 使用逗号作为列分隔符。默认情况下,PGFPlots 假定列由空格分隔。

相关内容