summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/pgfplots/test/numtabletest/numtabletest.tex
blob: 65eee3fd45120b3b701aaba3dfc1ad72bc1103a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
\documentclass[a4paper]{article}

\usepackage[intlimits]{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{ifpdf}
\usepackage{listings}
\usepackage{rotating}

\usepackage{array}
\usepackage{booktabs}
\usepackage{colortbl}

\lstset{basicstyle=\ttfamily\footnotesize,tabsize=16}

\ifpdf
\else
\def\pgfsysdriver{pgfsys-dvipdfm.def}
\fi
\usepackage{pgfplots}

\parindent=0pt

\def\testsection#1{\message{STARTING TEST SECTION '#1'}\section{#1}}
\def\testsubsection#1{\message{STARTING TEST SUBSECTION '#1'}\subsection{#1}}
\def\testsubsubsection#1{\message{STARTING TEST SUBSUBSECTION '#1'}\subsubsection{#1}}

\author{Christian Feuers\"anger}
\title{Test cases for pgfplotstable}

\begin{document}
\maketitle

\testsection{Reading a tab-separated table with many entries}
\begin{sidewaystable}
	\lstinputlisting{numtabletestdata}
\end{sidewaystable}
\testsubsection{Reading it...}
\tracingmacros=2\tracingcommands=2
\pgfplotstableread{numtabletestdata}\table
\tracingmacros=0\tracingcommands=0

\testsubsection{Quering colnames...}
%\tracingmacros=2\tracingcommands=2
\pgfplotstablegetcolumnlist\table\to\cols
\pgfplotslistforeach\cols\as\col{Column ``\col''\par}%
%\tracingmacros=0\tracingcommands=0

\testsubsection{Quering column content by column name}
%\tracingmacros=2\tracingcommands=2
\pgfplotstablegetcolumnbyname L2\of\table\to\colcontent
\pgfplotslistforeach\colcontent\as\colc{Row data: ``\colc''\par}%
%\tracingmacros=0\tracingcommands=0

\testsubsection{Quering column content by column name for all cols}
\pgfplotstablegetcolumnlist\table\to\cols
\pgfplotslistforeach\cols\as\col{\textbf{Column ``\col''}\par
	\pgfplotstablegetcolumnbyname\col\of\table\to\colcontent
	\pgfplotslistforeach\colcontent\as\colc{Row data: ``\colc''\par}%
}%

\testsection{Reading gnuplot output for use in 'plot file'}
\lstinputlisting{numtabletestdata2.gnuplot}
%\tracingmacros=2\tracingcommands=2
\pgfplotstableread{numtabletestdata2.gnuplot}\table
%\tracingmacros=0\tracingcommands=0

\testsubsection{Quering column content by column name for all cols}
\pgfplotstablegetcolumnlist\table\to\cols
\pgfplotslistforeach\cols\as\col{\textbf{Column ``\col''}\par
	\pgfplotstablegetcolumnbyname\col\of\table\to\colcontent
	\pgfplotslistforeach\colcontent\as\colc{Row data: ``\colc''\par}%
}%

\testsection{Table typesetting}
%
% Set this here globally:
\pgfplotstableset{/pgf/number format/sci zerofill}% any number in SCI format shall use zero filling.

\pgfplotstableread{numtabletestdata}\table

\testsubsection{no options at all}
\pgfplotstabletypeset\table

\testsubsection{Basis, L2, no options}
%\tracingmacros=2\tracingcommands=2
\pgfplotstabletypeset[columns={Basis,L2}]\table
%\tracingmacros=0\tracingcommands=0

\testsubsection{some column adjustments}
\pgfplotstabletypeset[
	columns={maxlevel,Basis,L2,cgiter},
	columns/maxlevel/.style={column name=$l_\infty$,column type=r},
	columns/cgiter/.style={column name={CG}},
	columns/L2/.style={column name={$L_2$},/pgf/number format/sci subscript,/pgf/number format/sci zerofill}]
	\table

\testsubsection{some row adjustments}
\pgfplotstabletypeset[
	/pgf/number format/sci subscript,/pgf/number format/sci zerofill,
	every head row/.style={before row=\toprule,after row=\midrule},
	every last row/.style={after row=\bottomrule},
	]
	\table


\testsubsection{coloring rows}

\pgfplotstabletypeset[
	every even row/.style={before row={\rowcolor[gray]{0.9}}},
	every head row/.style={before row=\toprule,after row=\midrule},
	every last row/.style={after row=\bottomrule},
	]
	\table

\testsubsubsection{writing to numtabletest.generated1.tex}%
\pgfplotstabletypeset[
	outfile=numtabletest.generated1.tex,
	every even row/.style={before row={\rowcolor[gray]{0.9}}},
	every head row/.style={before row=\toprule,after row=\midrule},
	every last row/.style={after row=\bottomrule},
	]
	\table

\testsubsubsection{loading numtabletest.generated1.tex}
\input{numtabletest.generated1.tex}

\testsubsection{Choosing columns by index}
%\tracingmacros=2\tracingcommands=2
\pgfplotstabletypeset[
	columns={[index]5,dof,[index]0}
	]
	\table
%\tracingmacros=0\tracingcommands=0

\testsubsection{column styles}
\pgfplotstabletypeset[
	every even column/.style={column type={>{\columncolor[gray]{.8}[\tabcolsep]}l}},
	]
	\table

\begingroup
\testsubsection{column styles + string type}
\pgfplotstableread{numtabletestdata2}\table
%\tracingmacros=2\tracingcommands=2
\pgfplotstabletypeset[
	every first column/.style={string type,column type={@{}r|},column name=},
	every head row/.style={after row=\hline},
	every even column/.style={column type={>{\columncolor[gray]{.8}[\tabcolsep]}l}},
	]
	\table
\endgroup

\begingroup
\testsubsection{column styles and special characters =/,}
\pgfplotstableread{numtabletestdata3}\table
\pgfplotstabletypeset[
	columns/{grad(log(dof),log(L2))}/.style={
		column name=$L_2$ slopes,
		/pgf/number format/fixed,
		/pgf/number format/precision=1,
		/pgf/number format/fixed zerofill},
	columns/L2/.style={
		column name=$L_2$,
		/pgf/number format/sci
	}
	]
	\table

\testsubsection{Input formats}
\tracingmacros=2\tracingcommands=2
{
\pgfplotstableset{columns/head/.style={string type}}
\testsubsubsection{comma}
\pgfplotstabletypesetfile[col sep=comma]{numtabletestdata2.csv}

\testsubsubsection{colon}
\pgfplotstabletypesetfile[col sep=colon]{numtabletestdata2.colon}

\testsubsubsection{semicolon}
\pgfplotstabletypesetfile[col sep=semicolon]{numtabletestdata2.semicolon}

\testsubsubsection{brace}
\pgfplotstabletypesetfile[col sep=braces]{numtabletestdata2.brace}
\tracingmacros=0\tracingcommands=0
}
\endgroup


{
\testsection{Col type}

\newcolumntype{L}[1]
	{>{\begin{pgfplotstablecoltype}[#1]}r<{\end{pgfplotstablecoltype}}}

\begin{tabular}{L{int detect}L{sci,sci subscript,sci zerofill}}
9      & 2.50000000e-01\\
25     & 6.25000000e-02\\
81     & 1.56250000e-02\\
289    & 3.90625000e-03\\
1089   & 9.76562500e-04\\
4225   & 2.44140625e-04\\
16641  & 6.10351562e-05\\
66049  & 1.52587891e-05\\
263169 & 3.81469727e-06\\
1050625& 9.53674316e-07\\
\end{tabular}

}

\end{document}