nipype.sphinxext.plot_workflow module

nipype.sphinxext.plot_workflow – Workflow plotting extension

A directive for including a nipype workflow graph in a Sphinx document.

This code is forked from the plot_figure sphinx extension of matplotlib.

By default, in HTML output, workflow will include a .png file with a link to a high-res .png. In LaTeX output, it will include a .pdf. The source code for the workflow may be included as inline content to the directive workflow:

.. workflow ::
    :graph2use: flat
    :simple_form: no

    from niflow.nipype1.workflows.dmri.camino.connectivity_mapping import create_connectivity_pipeline
    wf = create_connectivity_pipeline()

For example, the following graph has been generated inserting the previous code block in this documentation:


(Source code, png, svg, pdf)


The workflow directive supports the following options:
graph2use{‘hierarchical’, ‘colored’, ‘flat’, ‘orig’, ‘exec’}

Specify the type of graph to be generated.

simple_form: bool

Whether the graph will be in detailed or simple form.

format{‘python’, ‘doctest’}

Specify the format of the input


Whether to display the source code. The default can be changed using the workflow_include_source variable in


If this source file is in a non-UTF8 or non-ASCII encoding, the encoding must be specified using the :encoding: option. The encoding will not be inferred using the -*- coding -*- metacomment.

Additionally, this directive supports all of the options of the image directive, except for target (since workflow will add its own target). These include alt, height, width, scale, align and class.

Configuration options

The workflow directive has the following configuration options:

Select a graph type to use


determines if the node name shown in the visualization is either of the form nodename (package) when set to True or nodename.Class.package when set to False.


Default value for the include-source option


Whether to show a link to the source in HTML.


Code that should be executed before each workflow.


Base directory, to which workflow:: file names are relative to. (If None or empty, file names are relative to the directory where the file containing the directive is.)

File formats to generate. List of tuples or strings::

[(suffix, dpi), suffix, …]

that determine the file format and the DPI. For entries whose DPI was omitted, sensible defaults are chosen. When passing from the command line through sphinx_build the list should be passed as suffix:dpi,suffix:dpi, ….


Whether to show links to the files in HTML.


A dictionary containing any non-standard rcParams that should be applied before each workflow.


By default, rcParams are applied when context option is not used in a workflow directive. This configuration option overrides this behavior and applies rcParams before each workflow.


By default, the working directory will be changed to the directory of the example, so the code can get at its data files, if any. Also its path will be added to sys.path so it can import any helper modules sitting beside it. This configuration option can be used to specify a central directory (also added to sys.path) where data files and helper modules for all code are located.


Provide a customized template for preparing restructured text.

class nipype.sphinxext.plot_workflow.GraphError

Bases: RuntimeError

class nipype.sphinxext.plot_workflow.ImageFile(basename, dirname)

Bases: object

class nipype.sphinxext.plot_workflow.WorkflowDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)

Bases: docutils.parsers.rst.Directive

final_argument_whitespace = False
has_content = True
option_spec = {'align': <function _option_align>, 'alt': <function unchanged>, 'class': <function class_option>, 'context': <function _option_context>, 'encoding': <function encoding>, 'format': <function _option_format>, 'graph2use': <function _option_graph2use>, 'height': <function length_or_unitless>, 'include-source': <function _option_boolean>, 'nofigs': <function flag>, 'scale': <function nonnegative_int>, 'simple_form': <function _option_boolean>, 'width': <function length_or_percentage_or_unitless>}
optional_arguments = 2
required_arguments = 0
nipype.sphinxext.plot_workflow.format_template(template, **kw)
nipype.sphinxext.plot_workflow.mark_wf_labels(app, document)

To make graphs referenceable, we need to move the reference from the “htmlonly” (or “latexonly”) node to the actual figure node itself.

nipype.sphinxext.plot_workflow.out_of_date(original, derived)

Returns True if derivative is out-of-date wrt original, both of which are full file paths.


Remove the coding comment, which exec doesn’t like.

nipype.sphinxext.plot_workflow.render_figures(code, code_path, output_dir, output_base, context, function_name, config, graph2use, simple_form, context_reset=False, close_figs=False)

Run a nipype workflow creation script and save the graph in output_dir. Save the images under output_dir with file names derived from output_base

nipype.sphinxext.plot_workflow.run_code(code, code_path, ns=None, function_name=None)

Import a Python module from a path, and run the function given by name, if function_name is not None.


Extract code from a piece of text, which contains either Python code or doctests.