PHPackages                             macocci7/php-plotter2d - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. macocci7/php-plotter2d

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

macocci7/php-plotter2d
======================

A PHP Library to plot graphs and figures on a xy(-two-dimensional)-plane.

0.4.0(5mo ago)0186[1 issues](https://github.com/macocci7/PHP-Plotter2d/issues)3MITPHPPHP &gt;=8.1

Since Jul 2Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/macocci7/PHP-Plotter2d)[ Packagist](https://packagist.org/packages/macocci7/php-plotter2d)[ RSS](/packages/macocci7-php-plotter2d/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (15)Used By (3)

PHP-Plotter2d
=============

[](#php-plotter2d)

A PHP Library to plot graphs and figures on a xy(-two-dimensional)-plane.

1. Features
-----------

[](#1-features)

`PHP-Plotter2d` provides basic features to plot graphs and figures on a xy(-two-dimensional)-plane.

### 1.1. Canvas

[](#11-canvas)

You can draw figures freely on the canvas, such as: `Pixels`, `Lines`, `Boxes`, `Circles`, `Ellipses`, `Polygons` and `Bezier Curves`. You can also put `Text` or `Fill` the canvas with a specific color. You can save the `Canvas` to a file.

[![](examples/img/DrawOnCanvas.png)](examples/img/DrawOnCanvas.png)

### 1.2. Plotarea

[](#12-plotarea)

You can put figures within the `Plotarea` by just specifying the coordinates on the xy-plane without having to consider the pixel coordinates on the image. `Transformer` automatically maps the coordinates on the xy-plane to pixel coordinates on the image. `Plotarea` is automatically placed on the `Canvas`. You can adjust the position and the size of `Plotarea` on the `Canvas`.

[![](examples/img/PlotWithinPlotarea.png)](examples/img/PlotWithinPlotarea.png)

### 1.3. Transformer

[](#13-transformer)

You can use only `Transformer` separately from `Canvas` and `Plotarea`.

```
use Macocci7\PhpPlotter2d\Transformer;

$transformer = new Transformer(
    viewport: ['x' => [-1, 4], 'y' => [-2, 3]],
    plotarea: [
        'width' => 400,
        'height' => 400,
    ],
);

$points = $transformer->getCoords([
    [-0.5, -1.2],
    [1.3, 0.6],
    [3.4, 2.8],
]);
```

2. Contents
-----------

[](#2-contents)

- [1. Features](#1-features)
    - [1.1. Canvas](#11-canvas)
    - [1.2. Plotarea](#12-plotarea)
    - [1.3. Transformer](#13-transformer)
- 2. Contents
- [3. Requirements](#3-requirements)
- [4. Installation](#4-installation)
- [5. Usage](#5-usage)
    - [5.1. Handling Canvas](#51-handling-canvas)
    - [5.2. Handling Plotarea](#52-handling-plotarea)
    - [5.3. Handling Transformer](#53-handling-transformer)
- [6. Examples](#6-examples)
- [7. LICENSE](#7-license)

3. Requirements
---------------

[](#3-requirements)

- PHP 8.1 or later
- Imagick PHP Extension

    Check with commands:

    ```
    php -i | grep imagick
    ```
- Composer

4. Installation
---------------

[](#4-installation)

```
composer require macocci7/php-plotter2d
```

5. Usage
--------

[](#5-usage)

### 5.1. Handling Canvas

[](#51-handling-canvas)

To draw figures on the `Canvas`, create an instance of `Canvas` at first. Use `Plotter::make()` method to get an instance of `Canvas`. Pass the `width` and `height` of the `Canvas` in the `canvasSize` parameter.

```
