当我使用文件运行以下代码时data.txt
......
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\pgfplotstableread{data.txt}\Rtable
\begin{tikzpicture}
\begin{axis}[
xlabel={mu},
ylabel={f},
xmin=3, xmax=50,
ymin=50, ymax=100,
legend style={at={(axis cs:50,80)},anchor=south east,font=\tiny},
legend entries={$\eta=0.5$, $\eta=1.5$, $\eta=2.5$,$\eta=5$,$\eta=10$,$\eta=15$,$\eta=25$}
]
\addplot[color=magenta,mark=o,mark color=green] table[y = Eta05] from \Rtable ;
\addplot[color=teal,mark=square,mark color=green] table[y = Eta105] from \Rtable ;
\addplot[color=green,mark=*,mark color=green] table[y = Eta205] from \Rtable ;
\addplot[color=blue,mark=star,mark color=green] table[y = Eta5] from \Rtable ;
\addplot[color=cyan,mark=otimes,mark color=green] table[y = Eta10] from \Rtable ;
\addplot[color=red,mark=triangle,mark color=green] table[y = Eta15] from \Rtable ;
\addplot[color=orange,mark=x,mark color=green] table[y = Eta25] from \Rtable ;
\end{axis}
\end{tikzpicture}
\end{document}
我遇到了以下错误:
Package pgfplots Error: Table 'data.txt' appears to have too many coly.
Also verify that column names are plain ASCII.).
This error is not critical. ...pgfplotstableread{data.txt}\Rtable
Dimension too large. \end{axis}
Dimension too large. \end{axis}
running in backwards compatibility mode (unsuitable tick labels; missing features).
Consider writing \pgfplotsset{compat=1.12} into your preamble.
添加我的序言后\pgfplotsset{compat=1.12}
,仍然出现以下错误
Package pgfplots Error: Table 'data.txt' appears to have too many coly.
Also verify that column names are plain ASCII.). This error is not critical.
...pgfplotstableread{data.txt}\Rtable
Dimension too large. \end{axis}
Dimension too large. \end{axis}
Dimension too large. \end{axis}
但是当我添加
\begin{filecontents*}{data.csv}
mu & Eta05 & Eta105 & Eta205 & Eta5 & Eta10 & Eta15 & Eta25
2.5& 158.086810& 148.218338& 141.185738& 132.213683& 123.803119 &117.787777 &108.482610
3.0& 98.451835& 87.054289& 79.628072& 72.106007& 68. 486806& 67.002723& 65.169244
3.5& 85.401668& 74.166957& 67.125917& 60.992210& 59.808002& 59.948999 & 60.051464
4.0& 80.752934& 69.614034& 62.786944& 57.414396& 57.387458 & 58.159165 & 58.879482
4.5& 78.649980& 67.543726& 60.832928& 55.909321& 56.508328& 57.571088 & 58.532668
5.0& 77.574273& 66.465392& 59.817595& 55.176014& 56.147092 & 57.360550 & 58.427176
5.5& 76.983310& 65.852998& 59.238120& 54.782912 & 55.991561& 57.289748 & 58.404536
6.0& 76.644634& 65.483328& 58.883928& 54.557119 & 55.926289& 57.275203 & 58.412101
6.5& 76.446290& 65.249637& 58.655427& 54.420231 & 55.902972& 57.283827 & 58.430182
7.5& 76.262599& 64.992702& 58.393061& 54.276059 & 55.905690& 57.321824 & 58.471161
8.5& 76.208315& 64.869417& 58.255500& 54.208693& 55.927382& 57.360911 & 58.506102
9.5& 76.204858& 64.804256& 58.173757& 54.172047& 55.949867& 57.393085 & 58.532877
10.0& 76.211650& 64.783063& 58.144280& 54.159353& 55.959829 & 57.406375 & 58.543584
11.5& 76.244573& 64.742614& 58.080603 & 54.132025& 55.983407& 57.436788 & 58.567443
13.5& 76.292395& 64.713241& 58.025281 & 54.106536 & 56.002348 & 57.461302 & 58.586027
15 & 76.323304& 64.698158 & 57.994336 & 54.090627 & 56.010017 & 57.472000 & 58.593899
20 & 76.391403& 64.660545 & 57.919966 & 54.046219 & 56.015134 & 57.484401 & 58.602444
25 & 76.424631& 64.630563 & 57.868278 & 54.010977 & 56.008094 & 57.482538 & 58.600464
30 & 76.440877& 64.605689 & 57.829598 & 53.982983 & 55.998462 & 57.476841 & 58.595800
40 & 76.452460& 64.568135 & 57.776076 & 53.942674 & 55.980506 & 57.464379 & 58.585989
50 & 76.454123& 64.542162 & 57.741491 & 53.915912 & 55.966629 & 57.454055 & 58.577986
\end{filecontents*}
\pgfplotstableread[col sep=&]{data.csv}{\Rtable}
在序言中,它工作正常。我的初始代码有什么问题?
答案1
错误解释
在标有的列中的数据(不包括标题)的第二行中,Eta10
您在条目中有一个额外的空格68. 486806
。
由于您没有col sep
在\pgfplotstableread
命令中指定,因此使用初始值,即col sep=space
。此设置同时考虑空格和制表符(实际上,任何空格(换行符除外)作为列分隔符,从而在此行中为您提供一个额外的列;68.
被视为一列和486806
另一列。这会导致您收到错误。
可能的解决方案
为了解决这个问题,您可以:
只需删除文件中的多余空间即可
data.txt
。提供
col sep=tab
,如果出现多次此类格式错误的输入,则这是一种更灵活的解决方案,因为这只会将制表符视为列分隔符。因此,\pgfplotstableread[col sep=tab]{data.txt}\Rtable
应该能让你的代码工作。