8 $labelspace_x = "0.3cm";
9 $labelspace_y = "0.3cm";
11 sub set_data_bounds_from_data {
14 foreach $aref ( @$values ) {
21 $minx = $x if $x < $minx;
22 $maxx = $x if $x > $maxx;
23 $miny = $y if $y < $miny;
24 $maxy = $y if $y > $maxy;
29 ($minx, $miny, $maxx, $maxy) = @_;
32 sub setup_transforms {
35 $scalex = $box_width / ($maxx - $minx);
36 $scaley = $box_height / ($maxy - $miny);
39 sub set_picture_size {
40 ($box_width, $box_height) = @_;
48 $x = ($x + $addx) * $scalex;
49 $y = ($y + $addy) * $scaley;
51 if(defined($optional)) {
60 $x = ($x + $addx) * $scalex;
61 $y = ($y + $addy) * $scaley;
62 print "\\pgfpoint{${x}cm}{${y}cm}";
66 my ($tikzinterval_x, $tikzinterval_y) = @_;
70 \\draw (0, 0) rectangle +($box_width, $box_height);
74 for($t = $minx; $t < $maxx; $t += $tikzinterval_x) {
75 print "\t\t\\node at ";
76 outputcoord($t, $miny, "yshift=-$labelspace_x");
79 outputcoord($t, $miny);
81 outputcoord($t, $miny, "yshift=$tikzlen_x");
85 for($t = $miny; $t < $maxy; $t += $tikzinterval_y) {
86 print "\t\t\\node at ";
87 outputcoord($minx, $t, "xshift=-$labelspace_y");
90 outputcoord($minx, $t);
92 outputcoord($minx, $t, "xshift=$tikzlen_y");
108 VALUE: foreach $aref ( @$values ) {
111 next VALUE if !defined($x) || !defined($y);
112 next VALUE if $x < $minx or $x >= $maxx or $y < $miny or $y >= $maxy;
114 print "\t\t\\pgfplotstreampoint{";
124 sub draw_regression {
125 # see http://de.wikipedia.org/wiki/Regressionsanalyse#Berechnung_der_Regressionsgeraden
131 if (!defined($start_x)) { $start_x = $minx; }
132 if (!defined($end_x)) { $end_x = $maxx; }
137 V1: foreach $aref (@$values) {
140 next V1 if (!defined($x) || !defined($y));
142 if ($minx <= $x && $x <= $maxx && $miny <= $y && $y <= $maxy) {
152 my $denominator = 0.0;
153 V2: foreach $aref (@$values) {
156 next V2 if (!defined($x) || !defined($y));
158 if ($minx <= $x && $x <= $maxx && $miny <= $y && $y <= $maxy) {
159 $nominator += ($x - $avg_x) * ($y - $avg_y);
160 $denominator += ($x - $avg_x) * ($x - $avg_x);
163 my $b = $nominator / $denominator;
164 my $a = $avg_y - $b * $avg_x;
166 print "\t\\draw[$style] ";
167 outputcoord($start_x, $a + $start_x * $b);
169 outputcoord($end_x, $a + $end_x * $b);