test and codecov codecov CodeFactor

A package for combining/aranging multiple python ggplot visuals from plotnine. Internally, we leverage SVG objects and descriptions to accomplish it’s goals.


To install the current version of this package, please run

pip install cowpatch

If you would like to experiment with the development version of this package please following the guidelines in the contributing page.


import cowpatch as cow
import plotnine as p9
import as p9_data
import numpy as np
# creation of some some ggplot objects
g0 = p9.ggplot(p9_data.mpg) +\
    p9.geom_bar(p9.aes(x="hwy")) +\
    p9.labs(title = 'Plot 0')

g1 = p9.ggplot(p9_data.mpg) +\
    p9.geom_point(p9.aes(x="hwy", y = "displ")) +\
    p9.labs(title = 'Plot 1')

g2 = p9.ggplot(p9_data.mpg) +\
    p9.geom_point(p9.aes(x="hwy", y = "displ", color="class")) +\
    p9.labs(title = 'Plot 2')
vis_patch = cow.patch(g0,g1,g2)
vis_patch += cow.layout(design = np.array([[0,1],
                        rel_heights = [1,2]) = 11, height = 7)

cowpatch example

Please see additional documentation pages like “Getting-Started” and the individual pages on different plot arrangement strategies.

Future Goals

This package is currently in development (please feel welcome to contribute, with code, examples, issues, publicity, etc.). We envision a sequence of versions coming out with different added features in each. The order of the features will look something like the following

  • [x] MVP #1: base implimentation (reflecting cowplot and gridExtra functionality, minus labeling and titles)

  • [ ] MVP #2: figure labeling and titles and cow.text() objects

  • [ ] MVP #3: “Arithmetic of arrangement” (reflecting patchwork)

In addition, we envision the following features coming along in parallel:

  • [ ] inseting plots (like seen in cowplot)

  • [ ] wrapping of matplotlib, plotnine and seaborn plots to work within the cowpatch framework and within the patchwork framework

  • [ ] more complex drawing tools like the R package grid to allow for easy creation of complex features

For the interested reader, a lot of these ideas have been sketched in our notes/ folder as “proof of concepts”.

Package Logistics

Background and history

This package’s name is a merging of the names of R packages’ cowplot and patchwork. It attempts to provide similar plot arrangement and combination tools as gridExtra, cowplot and patchwork for the plotnine’s ggplot objects.

This package is not directly related to any of aforementioned packages (including the Wilke Lab, lead by Claus O. Wilke) but naturally stands on the shoulders of the contributions each of the packages made.

This package leverages a SVG backend to create the arangements. This may make the actual package a bit more “hacky” then some may like, but we hope it can still be of use to the community.


Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.


cowpatch was created by Benjamin LeRoy (benjaminleroy) and Mallory Wang (wangmallory). It is licensed under the terms of the MIT license.


This python package stands on the shoulders of many open-source tools, cowpatch structure was created with cookiecutter and the py-pkgs-cookiecutter template, the documentation leverages sphinx, and underlying testing leverages pytest, hypothesis and pytest-regression. See the full list of package dependencies on Github.