pandoc-pyplot: A Pandoc filter for including figures generated from Matplotlib

[ deprecated, documentation, gpl, library, program ] [ Propose Tags ]
Deprecated in favor of pandoc-plot

A pandoc filter for including figures generated from Matplotlib. Keep the document and Python code in the same location. Output from Matplotlib is captured and included as a figure.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,,,,,,,,, (info)
Change log
Dependencies base (>=4 && <5), containers, directory, filepath, hashable (>1 && <2), pandoc-pyplot, pandoc-types (>1.12 && <2), random (>1 && <2), temporary, text, typed-process [details]
License MIT
Author Laurent P. René de Cotret
Maintainer Laurent P. René de Cotret
Category Documentation
Home page
Bug tracker
Source repo head: git clone
Uploaded by LaurentRDC at 2019-03-27T22:15:52Z
Executables pandoc-pyplot
Downloads 7278 total (77 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-03-27 [all 1 reports]

Readme for pandoc-pyplot-

[back to package description]


Hackage version Stackage version (LTS) Stackage version (nightly) Build status

A Pandoc filter for generating figures with Matplotlib from code directly in documents

Inspired by sphinx's `plot_directive`, pandoc-pyplot helps turn Python code present in your documents to embedded Matplotlib figures.


The filter recognizes code blocks with the pyplot class present. It will run the script in the associated code block in a Python interpreter and capture the generated Matplotlib figure.

Basic example

Here is a basic example using the scripting matplotlib.pyplot API:

    import matplotlib.pyplot as plt

    plt.plot([0,1,2,3,4], [1,2,3,4,5])
    plt.title('This is an example figure')

Putting the above in, we can then generate the plot and embed it:

pandoc --filter pandoc-pyplot --output output.html


pandoc --filter pandoc-pyplot --output output.pdf

or any other output format you want. pandoc-pyplot is efficient, too: it will detect which figures should be re-generated, and skip the others.

There are more examples in the source repository, in the \examples directory.

In case of an output format that supports links (e.g. HTML), the embedded image generated by pandoc-pyplot will be a link to the source code which was used to generate the file. Therefore, other people can see what Python code was used to create your figures.


You can also specify a caption for your image. This is done using the optional caption parameter:

    ```{.pyplot caption="This is a simple figure"}
    import matplotlib.pyplot as plt

    plt.plot([0,1,2,3,4], [1,2,3,4,5])
    plt.title('This is an example figure')

Including scripts

If you find yourself always repeating some steps, inclusion of scripts is possible using the include parameter. For example, if you want all plots to have the ggplot style, you can write a very short preamble like so:

import matplotlib.pyplot as plt'ggplot')

and include it in your document as follows:

    plt.plot([0,1,2,3,4], [1,2,3,4,5])
    plt.title('This is an example figure')

Which is equivalent to writing the following markdown:

    import matplotlib.pyplot as plt'ggplot')

    plt.plot([0,1,2,3,4], [1,2,3,4,5])
    plt.title('This is an example figure')

This include parameter is perfect for longer documents with many plots. Simply define the style you want in a separate script! You can also import packages this way, or define functions you often use.



Windows binaries are available on GitHub. Place the executable in a location that is in your PATH to be able to call it.


Starting with pandoc-pyplot version, Windows installers are also made available thanks to Inno Setup.

From Hackage/Stackage

pandoc-pyplot is available on Hackage. Using the cabal-install tool:

cabal update
cabal install pandoc-pyplot

Similarly, pandoc-pyplot is available on Stackage:

stack update
stack install pandoc-pyplot

From source

Building from source can be done using stack or cabal:

git clone
cd pandoc-pylot
stack install # Alternatively, `cabal install`

Running the filter


This filter only works with the Matplotlib plotting library. Therefore, you a Python interpreter and at least Matplotlib installed. The Python interpreter is expected to be discoverable using the name "python" (as opposed to "python3", for example)

You can use the filter with Pandoc as follows:

pandoc --filter pandoc-pyplot --output output.html

In which case, the output is HTML. Another example with PDF output:

pandoc --filter pandoc-pyplot --output output.pdf

Python exceptions will be printed to screen in case of a problem.

pandoc-pyplot has a very limited command-line interface. Take a look at the help available using the -h or --help argument:

pandoc-pyplot --help

Usage as a Haskell library

To include the functionality of pandoc-pyplot in a Haskell package, you can use the makePlot :: Block -> IO Block function (for single blocks) or plotTransform :: Pandoc -> IO Pandoc function (for entire documents).

Usage with Hakyll

This filter was originally designed to be used with Hakyll. In case you want to use the filter with your own Hakyll setup, you can use a transform function that works on entire documents:

import Text.Pandoc.Filter.Pyplot (plotTransform)

import Hakyll

-- Unsafe compiler is required because of the interaction
-- in IO (i.e. running an external Python script).
makePlotPandocCompiler :: Compiler (Item String)
makePlotPandocCompiler =
    (unsafeCompiler . plotTransform)


Do not run this filter on unknown documents. There is nothing in pandoc-pyplot that can stop a Python script from performing evil actions. This is the reason this package is deemed unsafe in the parlance of Safe Haskell.