Skip to content

Pandoc-plot

Because doodl is based on Pandoc, other tools in the Pandoc ecosystem are also available, in particular Laurent P. René de Cotret's Pandoc-Plot package. Pandoc-Plot allows you to insert, among other things, Python scripts that use matplotlib to insert visualizations right into our Markdown documents. It works like this.

Once you've got a Python script that generates a (single) visualization that you like, you insert the script right into your document, offset as a code block, like this:

```{.matplotlib}
import seaborn as sns
df = sns.load_dataset("penguins")
sns.pairplot(df, hue="species")
```

To tell doodl to include the Pandoc-Plot when it calls pandoc, use the -p (or --plot) flag, like this:

bash
% doodl --plot file.md

Here is the output:

Matplotlib output

Some things to note:

  • The pandoc-plot Pandoc filter must be installed on your computer.
  • Any data that you load must be loaded for each matplotlib code block.
  • The code block must produce a single plot object.
  • You must not call plot.show().

The output plots will be generated in PNG, and placed in a plots folder for you, in the same folder that holds the output file, if doodl is run in formatter mode.

Note that Pandoc-Plot has more tricks than matplotlib up its sleeve. Here's a list, from the README in Pandoc-Plot's Github repository:

  • plotly_python : plots using the plotly Python library
  • plotly_r: plots using the plotly R library
  • matlabplot: plots using MATLAB
  • mathplot : plots using Mathematica
  • octaveplot: plots using GNU Octave
  • ggplot2: plots using ggplot2
  • gnuplot: plots using gnuplot
  • graphviz: graphs using Graphviz
  • bokeh: plots using the Bokeh visualization library
  • plotsjl: plots using the Julia Plots.jl package
  • plantuml: diagrams using the PlantUML software suite
  • sageplot: plots using the Sage software system
  • d2: plots using D2
  • asymptote: plots using Asymptote

For example, this GNU Octave script:

~~~{,octaveplot}
rand ("state", 2);
x = 0:0.1:10;
y = sin (x);
lerr = 0.1 .* rand (size (x));
uerr = 0.1 .* rand (size (x));
errorbar (x, y, lerr, uerr);
axis ([0, 10, -1.1, 1.1]);
xlabel ("x");
ylabel ("sin (x)");
title ("Errorbar plot of sin (x)");
~~~

would produce this:

Error bars

Released under the MIT License. | Privacy Policy