26 public double getMinY(
double[] height) {
27 double min = height[0];
28 for (
int i = 1; i < height.length; i++) {
39 public double getMaxY(
double[] height) {
40 double max = height[0];
41 for (
int i = 1; i < height.length; i++) {
56 double a = scaledH.
getA();
57 double b = scaledH.
getB();
59 double h = (b - a) / nBin;
60 double bound[] =
new double[nBin + 1];
62 for (
int i = 1; i <= nBin; i++)
63 bound[i] = bound[i - 1] + h;
88 public String toLatex(
ScaledHistogram scaledH,
boolean poly,
boolean hist) {
91 double bound[] = getHistogramBound(scaledH);
92 return toLatex(bound, height, poly, hist);
121 public String toLatex(
double[] bound,
double[] height,
boolean poly,
boolean hist) {
122 if (poly ==
false && hist ==
false) {
126 double h = (bound[1] - bound[0]) / 2;
127 double yMin = getMinY(height);
128 double yMax = getMaxY(height) + 0.2 * getMaxY(height);
129 Formatter formatter =
new Formatter(Locale.US);
130 formatter.format(
"\\documentclass[border=3mm, %n");
131 formatter.format(
" tikz, %n");
132 formatter.format(
" preview %n");
133 formatter.format(
" ]{standalone} %n%n");
134 formatter.format(
"\\usepackage{pgfplots}");
135 formatter.format(
"%n%n");
136 formatter.format(
"\\begin{document}%n%n");
137 formatter.format(
"%%---------------------------------------------------------------%%%n");
138 formatter.format(
"\\begin{tikzpicture} %n%n");
139 formatter.format(
"\\begin{axis}[ %n");
140 formatter.format(
" ymin=%s, ymax=%s,%n", yMin, yMax);
141 formatter.format(
" minor y tick num = 3, %n");
142 formatter.format(
" %%area style, %n");
143 formatter.format(
" ] %n");
145 formatter.format(
"\\addplot+[ybar interval,mark=no] plot coordinates { ");
146 for (
int i = 0; i < height.length; i++)
147 formatter.format(
"\n (%s,%s) ", bound[i], height[i]);
148 formatter.format(
"};%n%n");
151 formatter.format(
"\\addplot+[sharp plot] plot coordinates { ");
152 formatter.format(
"(%s,%s) ", bound[0], height[0]);
153 for (
int i = 0; i < height.length; i++)
154 formatter.format(
"\n (%s,%s) ", bound[i] + h, height[i]);
155 formatter.format(
"(%s,%s) ", bound[bound.length - 1], height[height.length - 1]);
156 formatter.format(
"};%n%n");
158 formatter.format(
"\\end{axis} %n%n");
159 formatter.format(
"\\end{tikzpicture} %n%n");
160 formatter.format(
"\\end{document}%n");
162 String ch = formatter.toString();
177 public void writeStringTofile(String name, String chaine)
throws IOException {
178 String currentDir = System.getProperty(
"user.dir");
179 File file =
new File(currentDir +
"/" + name +
".tex");
183 file.createNewFile();
184 final FileOutputStream stream =
new FileOutputStream(file,
true);
185 final PrintWriter out =
new PrintWriter(
new OutputStreamWriter(stream));