我有以下代码:
\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}
\usepgfplotslibrary{statistics}
\begin{document}
\pgfplotsset{width=7cm,compat=1.10}
\pgfplotstableread{
%\begin{filecontents}{test.dat}
miles
1
2
1
5
4
10
7
10
9
8
9
9
%\end{filecontents}
}\mytable
\pgfplotstablegetrowsof{\mytable}
\edef\numberofrows{\pgfplotsretval}
\begin{tikzpicture}
\begin{axis}[y=1.5cm,ymax=2]
\addplot+[boxplot] table[ y index=0, row sep=newline ]{\mytable}
%\addplot+[boxplot] table[row sep=\\,y index=0]{
%data\\ 1\\2\\1\\5\\4\\10\\ 7\\10\\9\\8\\9\\9\\ }
%[above]
%node at (boxplot box cs:\boxplotvalue{lower whisker},1) {\pgfmathprintnumber{\boxplotvalue{lower whisker}}}
%node at (boxplot box cs:\boxplotvalue{lower quartile},1) {\pgfmathprintnumber{\boxplotvalue{lower quartile}}}
%node[left] at (boxplot box cs:\boxplotvalue{median},0.5) {\pgfmathprintnumber{\boxplotvalue{median}}}
%node at (boxplot box cs:\boxplotvalue{upper quartile},1) {\pgfmathprintnumber{\boxplotvalue{upper quartile}}}
%node at (boxplot box cs:\boxplotvalue{upper whisker},1) {\pgfmathprintnumber{\boxplotvalue{upper whisker}}} ;
\end{axis}
\end{tikzpicture}
\end{document}
编译后得到:
! File ended while scanning use of \pgfplots@addplotimpl@table@fromfile.
如何实现 boxplot 可以处理的内联数据表?另外,我注释掉的标签怎么样?请注意,我还注释掉了从它自己的表中读取的 boxplot。我的用法有一个内联表和几种绘图类型。我搜索了手册但没有成功。提前感谢你的帮助。戴夫
答案1
(评论太长。)
您的代码似乎运行良好,包括注释。
\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}
\usepgfplotslibrary{statistics}
\begin{document}
\pgfplotsset{width=7cm,compat=1.10}
\pgfplotstableread{
%\begin{filecontents}{test.dat}
miles
1
2
1
5
4
10
7
10
9
8
9
9
%\end{filecontents}
}\mytable
\pgfplotstablegetrowsof{\mytable}
\edef\numberofrows{\pgfplotsretval}
\begin{tikzpicture}
\begin{axis}[y=1.5cm,ymax=2]
\addplot+[boxplot] table[ y index=0, row sep=newline ]{\mytable}
node at (boxplot box cs:\boxplotvalue{lower whisker},1) {\pgfmathprintnumber{\boxplotvalue{lower whisker}}}
node at (boxplot box cs:\boxplotvalue{lower quartile},1) {\pgfmathprintnumber{\boxplotvalue{lower quartile}}}
node[left] at (boxplot box cs:\boxplotvalue{median},0.5) {\pgfmathprintnumber{\boxplotvalue{median}}}
node at (boxplot box cs:\boxplotvalue{upper quartile},1) {\pgfmathprintnumber{\boxplotvalue{upper quartile}}}
node at (boxplot box cs:\boxplotvalue{upper whisker},1) {\pgfmathprintnumber{\boxplotvalue{upper whisker}}};
\end{axis}
\end{tikzpicture}
\end{document}