The MPLW is Matplotlib (MPL) wrapper, which can work as AsciiDoc filter. Using this filter you can generate plots from inline matplotlib scripts.

Introduction

Matplotlib (MPL) is python charting library, with function similar to Gnuplot and interface modelled on Matlab API. AsciiDoc is converter from ascii text files (with human readable markup) to html and other doc formats.

Let say we need include sin(x) plot below into asciidoc document.

example-sin.png

We just include following MPL code snippet:

["mpl", "example-sin.png"]
-------------------------------------------
figure(figsize=(4,2))           # PNG size, inches
X = arange(0, 6, 0.1)           # 0, 0.1, 0.2 ... 6.0
Y = sin(X)                      # vector op
plot(X,Y)
-------------------------------------------

On first line in square brackets there are two parameters. First - "mpl" is name of asciidoc filter. Second is file name of your choice to store generated chart

Asciidoc will send inline python code between "----" lines to stdin of mplw.py, and generate HTML file with <img …> tag for MPLW produced PNG file.

flow.png

Now let say we have some data from two experiments and we need to plot it:

example-data.png

It can be made with this snippet:

["mpl", "example-data.png"]
-------------------------------------------
figure(figsize=(5,2.5))
title('Two Charts')
xlabel('Some text')
plot(c[0],c[1])         # x, y1
plot(c[0],c[2])         # x, y2
                        # columns below:  x, y1, y2
___________________________________________
1.0,    2.0,    1.0
2.0,    4.0,    1.2
3.0,    4.5,    1.6
4.0,    5.0,    3.3
5.0,    5.2,    4.4
-------------------------------------------

Text after "__" is plot data in table form. The c[][] is matrix where c[0] is vector holding 1st column from above table, c[1] is second column and so on. You can store plot data in in external file if needed, see matplotlib manual.

To see what MatPlotLib is capable of go to matplotlib gallery.

Install

Replace emerge with your distro package manager:

emerge -u matplotlib git
git clone git://github.com/lvv/mplw.git
cd mplw.git
make install          # this will create 2 files: /usr/share/asciidoc/filters/mpl/{mpl.conf,mplw.py}

Your disros might have different location for storing asciidoc’s filters. Default is /usr/share/asciidoc/filters. If this is not the case, you need to modify ASCIIDOC_FILTERS variable in Makefile.

Caution Matplotlib is pre-1.0 version which means it has unstable API and it might be not easy to install. From this are very stringent dependencies version requirements. Using bleeding edge and installing from source might be required.

MPLW works best with Matplotlib version 0.98 or higher. With lower versions MPLW style will be set to "none". But you can style your plot by using Mutplotlib commands in snippet. Matplotlib-0.98 is not compatible with python-2.6, version 0.99 is compatible with python-2.6. See also matplotlib install instruction.

Upstream "best" versions As of 8/9/2009:

How MPLW API differ from MPL

MPL API was somewhat simplified for use as AsciiDoc filter.

from matplotlib.pyplot import *
from numpy import *

Currently there is "asciidoc" — only and default style recognized by MPLW. When style is a "asciidoc", mplw will:

About

MPLW is based on GNU licensed graphviz2png.py by Gouichi Iisaka. MPLW is currently in alpha state, API not yet stable.

Todo

References