SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
PgfDataTable.java
1package umontreal.ssj.stat;
2
3import java.util.Arrays;
4import java.util.ArrayList;
5
15
16public class PgfDataTable {
17
18 String tableName; // The name of the table, as a character string.
19 String tableLabel; // A label (short name) that might be used to identify the curve in plots.
20 String[] fields; // The names of the fields. Should be short.
21 double[][] data; // The data points. data[s][j] for observation s, field j.
22 int numFields; // Number of fields for each data point.
23 int numObservations; // Number of observations (data points).
24
36 public PgfDataTable(String tableName, String tableLabel, String[] fields, double[][] data) {
37 super();
38 this.tableName = tableName;
39 this.tableLabel = tableLabel;
40 this.fields = fields;
41 this.data = data;
42 numFields = fields.length;
43 numObservations = data.length;
44 }
45
53 public String formatTable() {
54 StringBuffer sb = new StringBuffer("");
55 sb.append("% " + tableName + "\n ");
56 for (int j = 0; j < numFields; j++) // For each field j
57 sb.append(fields[j] + " ");
58 sb.append("\n");
59 for (int s = 0; s < numObservations; s++) { // For each cardinality n
60 for (int j = 0; j < numFields; j++) // For each field j
61 sb.append(" " + data[s][j]);
62 sb.append("\n");
63 }
64 return sb.toString();
65 }
66
76 public String formatTableTwoFields(int j1, int j2) {
77 StringBuffer sb = new StringBuffer("");
78 // sb.append("% " + tableName + "\n");
79 sb.append(" " + fields[j1] + " " + fields[j2] + " \n");
80 for (int s = 0; s < numObservations; s++) // For each cardinality n
81 sb.append(" " + data[s][j1] + " " + data[s][j2] + " \n");
82 return sb.toString();
83 }
84
96 public String formatPgfCurveAddPlot(int j1, int j2, String plotoptions) {
97 StringBuffer sb = new StringBuffer("");
98 sb.append(" \\addplot " // [" + plotoptions + "]
99 + "table[x=" + fields[j1] + ",y=" + fields[j2] + "] { \n");
100 sb.append(formatTableTwoFields(j1, j2) + " }; \n");
101 sb.append(" \\addlegendentry{" + tableLabel + "}\n");
102 sb.append(" \\label{" + tableLabel + "}\n");
103 sb.append("% \n");
104 return sb.toString();
105 }
106
116 public String formatPgfCurveAddPlot(String xaxis, String yaxis, String plotoptions) {
117 int j1 = Arrays.asList(fields).indexOf(xaxis);
118 int j2 = Arrays.asList(fields).indexOf(yaxis);
119 return formatPgfCurveAddPlot(j1, j2, plotoptions);
120 }
121
134 public String drawPgfPlotSingleCurve(String title, String axistype, String xaxis, String yaxis, int logbasis,
135 String axisoptions, String plotoptions) {
136 int j1 = Arrays.asList(fields).indexOf(xaxis);
137 int j2 = Arrays.asList(fields).indexOf(yaxis);
138 return drawPgfPlotSingleCurve(title, axistype, j1, j2, logbasis, axisoptions, plotoptions);
139 }
140
144 public String drawPgfPlotSingleCurve(String title, String axistype, int j1, int j2, int logbasis, String axisoptions,
145 String plotoptions) {
146 StringBuffer sb = new StringBuffer("");
147 sb.append(" \\begin{tikzpicture} \n");
148 sb.append(" \\begin{" + axistype + "}[ \n");
149 sb.append(" title ={" + title + "},\n");
150 sb.append(" xlabel=" + fields[j1] + ",\n");
151 sb.append(" ylabel=" + fields[j2] + ",\n");
152 if (axistype == "loglogaxis")
153 sb.append(" log basis x=" + logbasis + ", log basis y=" + logbasis + ",\n");
154 sb.append(" grid,\n");
155 sb.append(axisoptions + ",\n");
156 sb.append(" ] \n");
157 sb.append(formatPgfCurveAddPlot(j1, j2, plotoptions));
158 sb.append(" \\end{" + axistype + "}\n");
159 sb.append(" \\end{tikzpicture}\n");
160 sb.append(" ");
161 return sb.toString();
162 }
163
179 public static String drawPgfPlotManyCurves(String title, String axistype, int j1, int j2,
180 ArrayList<PgfDataTable> listCurves, int logbasis, String axisoptions, String plotoptions) {
181 StringBuffer sb = new StringBuffer("");
182 sb.append(" \\begin{tikzpicture} \n");
183 sb.append(" \\begin{" + axistype + "}[ \n");
184 sb.append(" title ={" + title + "},\n");
185 sb.append(" xlabel=" + listCurves.get(0).fields[j1] + ",\n");
186 sb.append(" ylabel=" + listCurves.get(0).fields[j2] + ",\n");
187 if (axistype == "loglogaxis")
188 sb.append(" log basis x=" + logbasis + ", log basis y=" + logbasis + ",\n");
189 sb.append(" grid,\n");
190 sb.append(axisoptions + ",\n");
191 // sb.append(" legend style={xshift=-3em,yshift=-2em}\n");
192 sb.append(" ] \n");
193 for (PgfDataTable curve : listCurves) {
194 sb.append(curve.formatPgfCurveAddPlot(j1, j2, plotoptions));
195 }
196 sb.append(" \\end{" + axistype + "}\n");
197 sb.append(" \\end{tikzpicture}\n");
198 sb.append(" ");
199 return sb.toString();
200 }
201
210 public String formatTableThreeFields(int j1, int j2, int j3) {
211 StringBuffer sb = new StringBuffer("");
212 // sb.append("% " + tableName + "\n");
213 // sb.append(" ( " + fields[j1] + ", " + fields[j2] + " , " + fields[j3]+ "
214 // )\n");
215 for (int s = 0; s < numObservations; s++) // For each cardinality n
216 sb.append(" ( " + data[s][j1] + " , " + data[s][j2] + " ," + data[s][j3] + ") \n");
217 return sb.toString();
218 }
219
232 public String formatPgfCurveAddPlot(int j1, int j2, int j3, String plotoptions) {
233 StringBuffer sb = new StringBuffer("");
234 sb.append(" \\addplot3 " + "[" + plotoptions + "]" + "coordinates" + " { \n");
235 sb.append(formatTableThreeFields(j1, j2, j3) + " }; \n");
236 sb.append(" \\addlegendentry{" + tableLabel + "}\n");
237 sb.append(" \\label{" + tableLabel + "}\n");
238 // sb.append("% \n");
239 return sb.toString();
240 }
241
256 public String drawPgfPlotSingleCurve(String title, String axistype, int j1, int j2, int j3, int logbasis,
257 String axisoptions, String plotoptions) {
258 StringBuffer sb = new StringBuffer("");
259 sb.append(" \\begin{tikzpicture} \n");
260 sb.append(" \\begin{" + axistype + "}[ \n");
261 sb.append(" title ={" + title + "},\n");
262 sb.append(" xlabel=" + fields[j1] + ",\n");
263 sb.append(" ylabel=" + fields[j2] + ",\n");
264 sb.append(" zlabel=" + fields[j3] + ",\n");
265
266 if (axistype == "loglogaxis")
267 sb.append(" log basis x=" + logbasis + ", log basis y=" + logbasis + ",\n");
268 sb.append(" grid,\n");
269 sb.append(" " + axisoptions + ",\n");
270 sb.append(" ] \n");
271 sb.append(formatPgfCurveAddPlot(j1, j2, j3, plotoptions));
272 sb.append(" \\end{" + axistype + "}\n");
273 sb.append(" \\end{tikzpicture}\n");
274 sb.append(" ");
275 return sb.toString();
276 }
277
278 public static String pgfplotFileHeader() {
279 StringBuffer sb = new StringBuffer("");
280 sb.append("\\documentclass[12pt]{article}\n" + "\\usepackage{pgfplots}\n" + "\\pgfplotsset{compat=1.12}\n"
281 + "\\usepackage{xcolor}\n" + "\\usetikzlibrary{shapes,decorations,arrows,automata,plotmarks,patterns}\n"
282 + "\\usepackage{tikz-inet}\n" + "\\usepgfplotslibrary{groupplots}\n" + "%\n"
283 + "\\pgfplotscreateplotcyclelist{defaultcolorlist}{%\n"
284 + " {blue!85!black,line width=0.9pt,mark=*,solid},\n"
285 + " {red!85!black,line width=0.9pt,mark=square*,dashed},\n"
286 + " {lime!60!black,line width=0.9pt,mark=triangle*,dotted},\n"
287 + " {orange!90!black,line width=0.9pt,mark=diamond*,loosely dashed},\n"
288 + " {black,mark=star,loosely dotted},\n" + " {violet!85!black,mark=o,solid},\n"
289 + " {brown!85!black,mark=square,dashed},\n" + " {purple!85!black,mark=triangle,dotted}}\n" + "%\n"
290 + "\\pgfplotsset{\n" + " every axis/.append style={\n" + " font=\\footnotesize,\n"
291 + " width=.8\\columnwidth,\n" + " height=.6\\columnwidth,\n" + " %!line width=0.6pt,\n"
292 + " legend style={at={(1.02,1)}, anchor={north west}},\n" + " cycle list name=defaultcolorlist,\n"
293 + " },\n" + " every axis title/.style={\n" + " at={(0.5,1)},\n" + " below\n" + " },\n }\n" + "%\n"
294 + "\\begin{document}\n\n");
295 return sb.toString();
296 }
297
298 public static String pgfplotEndDocument() {
299 return "\\end{document}\n";
300 }
301}
String formatTable()
Formats the full table as a String, with the field names in the first row, and the data points (obser...
String drawPgfPlotSingleCurve(String title, String axistype, int j1, int j2, int j3, int logbasis, String axisoptions, String plotoptions)
Same as drawPgfPlotSingleCurve(String, String, int, int, int, String,String) but for three-dimensiona...
static String drawPgfPlotManyCurves(String title, String axistype, int j1, int j2, ArrayList< PgfDataTable > listCurves, int logbasis, String axisoptions, String plotoptions)
Returns a string that contains a complete tikzpicture for the pgfplot package, showing the field j2 a...
String formatPgfCurveAddPlot(int j1, int j2, int j3, String plotoptions)
Similar to formatPgf, but outputs complete LaTeX code in an appropriate format that adds a curve of t...
String drawPgfPlotSingleCurve(String title, String axistype, String xaxis, String yaxis, int logbasis, String axisoptions, String plotoptions)
Returns a String that contains a complete tikzpicture for the pgfplot package, showing the field j2 a...
String formatTableTwoFields(int j1, int j2)
Similar to formatTable, but retains only two selected columns of the table (i.e., two selected fields...
String drawPgfPlotSingleCurve(String title, String axistype, int j1, int j2, int logbasis, String axisoptions, String plotoptions)
Similar to the previous one.
String formatTableThreeFields(int j1, int j2, int j3)
Similar to formatTableTwoFields(int, int), but for three fields.
PgfDataTable(String tableName, String tableLabel, String[] fields, double[][] data)
Constructs a table with the given table name, array of field names, and data observations.
String formatPgfCurveAddPlot(String xaxis, String yaxis, String plotoptions)
In this version, the two fields are specified by their names in the table.
String formatPgfCurveAddPlot(int j1, int j2, String plotoptions)
Similar to formatTableTwoFields, but outputs complete LaTeX code in an appropriate format that adds a...