-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphLogCurve.php
More file actions
70 lines (62 loc) · 1.75 KB
/
Copy pathGraphLogCurve.php
File metadata and controls
70 lines (62 loc) · 1.75 KB
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
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Macocci7\PhpPlotter2d\Plotter;
// Instantiation
$size = 400;
$viewport = ['x' => [-1, 4], 'y' => [-2, 3]];
$plotarea = [ // full size
'offset' => [0, 0],
'width' => $size,
'height' => $size,
];
$canvas = Plotter::make(
canvasSize: ['width' => $size, 'height' => $size],
viewport: $viewport,
plotarea: $plotarea,
);
// plotting grids and axis
$fontPath = '/usr/share/fonts/opentype/ipafont-mincho/ipamp.ttf';
$gridInterval = 0.5;
$canvas
->plotGridHorizon($gridInterval, 1, '#ccffcc')
->plotGridVertical($gridInterval, 1, '#ccffcc')
->plotGridValuesX($gridInterval * 2)
->plotGridValuesY($gridInterval * 2)
->plotAxisX()
->plotAxisY()
->plotAxisLabelO('O', size: 18, fontPath: $fontPath)
->plotAxisLabelX('M', size: 18, fontPath: $fontPath, position: 'upper')
->plotAxisLabelY('N', size: 18, fontPath: $fontPath, position: 'right');
// plotting logarithmic curve
$dx = 0.1;
for ($x = 0.1; $x < 4; $x += $dx) {
$canvas->plotline(
x1: $x,
y1: log($x, 2),
x2: $x + $dx,
y2: log($x + $dx, 2),
width: 1,
color: '#0000ff',
);
}
// plot formula
$canvas->plotText(
text: 'N=logM/log2',
x: 3.9,
y: 2.1,
fontSize: 24,
fontPath: $fontPath,
fontColor: '#333333',
align: 'right',
valign: 'bottom',
);
// plot specific points and auxiliary lines
$x = 2;
$y = log($x, 2);
$canvas
->plotLine($x, $y, 0, $y, 1, '#ff0000', [8, 6])
->plotLine($x, $y, $x, 0, 1, '#ff0000', [8, 6])
->plotCircle($x, $y, 0.1, '#ff0000', 0)
->plotText("({$x}, {$y})", 2.25, 1.0, 24, $fontPath, '#333333', 'left', 'top');
// saving into the file
$canvas->save(__DIR__ . '/img/GraphLogCurve.png');