-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.php
196 lines (146 loc) · 4.71 KB
/
example.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/** example.php // example file for php-plotlib.class.php
*
*
* @author Rafael Martin Soto
* @author {@link https://www.inatica.com/ Inatica}
* @blog {@link https://rafamartin10.blogspot.com/ Blog Rafael Martin Soto}
* @since October 2021
* @version 1.0.0
* @license GNU General Public License v3.0
*
* */
require __DIR__ . '/php-plotlib.class.php';
?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Example PHP-PlotLib</title>
<meta name="description" content="Example PHP-PlotLib">
<meta name="author" content="SitePoint">
<meta property="og:title" content="Example PHP-PlotLib">
<meta property="og:type" content="website">
<meta property="og:url" content="https://www.inatica.com">
<meta property="og:description" content="Example PHP-PlotLib">
</head>
<body>
<?php
$plt = new php_plotlib();
$plt->plot( [1, 1.5, 2, 1.8, 3] );
$plt->plot( [2, 2.8, 1.7, 2, 2.3] );
$plt->title("Multi Line");
?>
<img src="<?php echo $plt->output_gd_png_base64( );?>">
<?php
unset($plt);
$plt = new php_plotlib();
$x = $plt->math->linspace( 0, 2, 50 );
$plt->plot( $x, $x, ['label'=>'linear'] );
$plt->plot( $x, $plt->math->pow($x, 2), ['label'=>'quadratic'] );
$plt->plot( $x, $plt->math->pow($x, 3), ['label'=>'cubic'] );
$plt->xlabel('x label');
$plt->ylabel('y label');
$plt->title("Simple Plot. With Legend & Labels X, Y");
$plt->legend( );
?>
<img src="<?php echo $plt->output_gd_png_base64( );?>">
<?php
unset($plt);
$plt = new php_plotlib();
$plt->bar( [1, 2, 3, 4], [10, 9, 10, 8] );
$plt->bar( [1, 2, 3, 4], [8, 6, 9, 7] );
$plt->bar( [1, 2, 3, 4], [6, 5, 7, 5] );
$plt->bar( [1, 2, 3, 4], [3, 3, 4, 2] );
$plt->axes([0, 6, 0, 20]);
$plt->title( 'Multi Bar & fixed Axis Values' );
?>
<img src="<?php echo $plt->output_gd_png_base64( );?>">
<?php
unset($plt);
$plt = new php_plotlib();
$plt->bar( [1, 2, 3, 4, 5, 6, 7], [1, 4, 9, 16, 17, 18, 17] );
$plt->plot( [1, 2, 3, 4, 5, 6, 7], [10,8, 5, 10,15, 16, 15] );
$plt->title( 'Bar & Line' );
?>
<img src="<?php echo $plt->output_gd_png_base64( );?>">
<?php
unset($plt);
$plt = new php_plotlib();
$x = $plt->math->linspace( 0, 5, 20 );
$plt->plot( [ [$x, $x, 'r--'], [$x, $plt->math->pow($x, 2), 'bs'], [$x, $plt->math->pow($x, 3), 'g^'] ] );
$plt->title( 'Colors, disctont. line & markers "--", "square", "^"' );
?>
<img src="<?php echo $plt->output_gd_png_base64( );?>">
<?php
unset($plt);
$plt = new php_plotlib();
$arr_values = [
[ [1, 1.5, 2, 2, 3, 4], [10, 9.5, 9, 10, 8, 9] ],
[ [4, 5, 5.7, 6, 7, 8], [8, 6, 7.3, 8, 7, 8] ],
];
$plt->title( 'Scatter' );
$plt->scatter( $arr_values );
?>
<img src="<?php echo $plt->output_gd_png_base64( );?>">
<?php
unset($plt);
$plt = new php_plotlib();
$plt->subplots( 2 );
$plt->subplots[0]->bar( [1, 2, 3, 4] );
$plt->subplots[1]->bar( [10, 20, 30, 40] );
?>
<img src="<?php echo $plt->subplots[0]->output_gd_png_base64( );?>">
<br />
<img src="<?php echo $plt->subplots[1]->output_gd_png_base64( );?>">
<?php
unset($plt);
print "<br />";
$plt = new php_plotlib();
$plt->subplots( 2, 2 );
$plt->subplots[0][0]->bar( [1, 2, 3, 4] );
$plt->subplots[0][1]->bar( [10, 20, 30, 40] );
$plt->subplots[1][0]->bar( [100, 200, 300, 400] );
$plt->subplots[1][1]->bar( [11, 12, 13, 14] );
?>
<img src="<?php echo $plt->subplots[0][0]->output_gd_png_base64( );?>">
<img src="<?php echo $plt->subplots[0][1]->output_gd_png_base64( );?>">
<br />
<img src="<?php echo $plt->subplots[1][0]->output_gd_png_base64( );?>">
<img src="<?php echo $plt->subplots[1][1]->output_gd_png_base64( );?>">
<?php
unset($plt);
print "<br />";
$plt = new php_plotlib();
$plt->subplots( 2, 2, ['figsize'=>[9,6], 'bordertype'=>'halfsquare'] );
$plt->subplots[0][0]->bar( [1, 2, 3, 4] );
$plt->subplots[0][1]->bar( [10, 20, 30, 40] );
$plt->subplots[1][0]->bar( [100, 200, 300, 400] );
$plt->subplots[1][1]->bar( [11, 12, 13, 14] );
?>
<img src="<?php echo $plt->subplots[0][0]->output_gd_png_base64( );?>">
<img src="<?php echo $plt->subplots[0][1]->output_gd_png_base64( );?>">
<br />
<img src="<?php echo $plt->subplots[1][0]->output_gd_png_base64( );?>">
<img src="<?php echo $plt->subplots[1][1]->output_gd_png_base64( );?>">
<?php
unset($plt);
print "<br />";
// read csv
$dataset = [];
if (($gestor = fopen("ibex35.csv", "r")) !== FALSE) {
while (($datos = fgetcsv($gestor, 1000, ",")) !== FALSE) {
$dataset[] = $datos;
}
fclose($gestor);
}
$plt = new php_plotlib();
$plt->pairplot( $dataset );?>
<img width="1900" src="<?php echo $plt->output_gd_png_base64( );?>"><?php
//print "<br />";
//$plt->pairplot( $dataset, ['widthmarker'=>6] );
unset($plt);
print "<br />";
?>
</body>
</html>