Skip to content

Commit 12f020d

Browse files
authored
Add files via upload
1 parent e773c24 commit 12f020d

7 files changed

+7721
-0
lines changed

example.php

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

0 commit comments

Comments
 (0)