-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsingLayers.php
71 lines (61 loc) · 1.92 KB
/
UsingLayers.php
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
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Macocci7\PhpScatterplot\Scatterplot;
$layers = [
'John' => [
'x' => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ],
'y' => [ 1, 2, 3, 4, 5, 8, 4, 7, 11, 9, 1, ],
],
'Jake' => [
'x' => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ],
'y' => [ 11, 8, 10, 7, 9, 6, 5, 3, 4, 2, 1, ],
],
'Hugo' => [
'x' => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ],
'y' => [ 4, 8, 10, 1, 9, 6, 5, 3, 7, 1, 11, ],
],
'Alex' => [
'x' => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ],
'y' => [ 3, 5, 11, 4, 8, 2, 9, 10, 1, 11, 7, ],
],
];
$legends = array_keys($layers);
$sp = new Scatterplot();
$sp->layers($layers)
->plotSize(6)
->legends($legends)
->labelX('Data X')
->labelY('Data Y')
->caption('Using Layers')
->create('img/UsingLayers.png');
// Markdown -------------------------------------
// Headline
echo "# PHP-Scatterplot : Using Layers\n\n";
// Layers
echo "<details><summary>Layers</summary>\n\n";
$dataCount = count($layers['Jake']['x']);
$columns = [];
foreach ($layers as $name => $layer) {
$columns[] = $name . ": x";
$columns[] = $name . ": y";
}
echo "|#|" . implode('|', $columns) . "|\n";
echo "|" . implode('|', array_fill(0, count($legends) * 2 + 1, ':---:')) . "|\n";
for ($i = 0; $i < $dataCount; $i++) {
$columns = [];
foreach ($layers as $layer) {
$columns[] = $layer['x'][$i];
$columns[] = $layer['y'][$i];
}
echo "|" . $i . "|" . implode('|', $columns) . "|\n";
}
echo "</details>\n\n";
// Regression Line Formula
echo "<details><summary>Regression Line Formula</summary>\n\n";
foreach ($layers as $name => $layer) {
$formula = $sp->regressionLineFormula($layer['x'], $layer['y']);
echo "- " . $name . ": y = " . $formula['a'] . " x + " . $formula['b'] . "\n";
}
echo "</details>\n\n";
// Scatter plot
echo "![UsingLayers.png](img/UsingLayers.png)\n";