collections-benchmark/matplotlib-d
Les De Ridder 2be5cd88bc Add plots and concat test 2019-07-10 02:37:24 +02:00
..
examples Add plots and concat test 2019-07-10 02:37:24 +02:00
python Add plots and concat test 2019-07-10 02:37:24 +02:00
source/matplotlibd Add plots and concat test 2019-07-10 02:37:24 +02:00
.gitignore Add plots and concat test 2019-07-10 02:37:24 +02:00
.travis.yml Add plots and concat test 2019-07-10 02:37:24 +02:00
LICENSE Add plots and concat test 2019-07-10 02:37:24 +02:00
README.md Add plots and concat test 2019-07-10 02:37:24 +02:00
dub.json Add plots and concat test 2019-07-10 02:37:24 +02:00

README.md

matplotlib-d

MIT License Build Status Dub version Dub download

2D Plotting library for D using python and matplotlib.

Requirements

  • Python
  • matplotlib

matplotlib-d uses python3 by default, thus if you want to use python2, set $MATPLOTLIB_D_PYTHON to python2.

Usage

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json: "matplotlib-d": "~>0.1.4"
dub.sdl: dependency "matplotlib-d" version="~>0.1.4"

For small applications or scripts, add following sentence to the head of your script.

#!/usr/bin/env dub
/+ dub.sdl:
	name "name_of_your_application"
	dependency "matplotlib-d" version="~>0.1.4"
+/

And excute with dub run --single.
For more details, please refer to the documentation of dub.

Syntax

Most pyplot functions are available.
For more details for each functions, please refer to the documantation of pyplot.
Describe Python keyword arguments as an associative array with string of keyword name as key.

  • The Python way:
    function(arg1, arg2..., keyword1=kwarg1, keyword2=kwarg2...)
  • The D way:
    function(arg1, arg2..., ["keyword1": kwarg1], ["keyword2": kwarg2])

Examples

Simple example:

import std.math;
import std.range;
import std.algorithm;
import plt = matplotlibd.pyplot;

void main() {
	auto x = iota(0, 2.05, 0.05).map!(x => x * PI);
	auto y = x.map!(sin);

	plt.plot(x, y, "r-", ["label": "$y=sin(x)$"]);
	plt.xlim(0, 2 * PI);
	plt.ylim(-1, 1);
	plt.legend();
	plt.savefig("simple.png");
	plt.clear();
}

Simple example

Color plot example:

import std.range;
import plt = matplotlibd.pyplot;

void main() {
	const n = 100;
	auto x = iota(n);
	auto y = x[];
	double[n][n] z;
		
	foreach (i; 0..n)
		foreach (j; 0..n)
			z[i][j] = i + j;
	    
	plt.contourf(x, y, z, 64, ["cmap": "hsv"]);
	plt.colorbar();
	plt.savefig("color.png");
	plt.clear();
}

Color plot example