Getting started

Please see the Guides tab to find more thorough examples.

After installing cowpatch, you can combine your plot objects together in different arrangements with different combinations of cow.patch and cow.layout.

Creating plots to combine

Before we start arranging, we load common python packages we use to create some basic plots.

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')

Arranging plots

To arrange these plots into a single patchwork, we first group the plots together with cow.patch and define a cow.layout that will define the layout of the plots.

vis_patch = cow.patch(g0,g1,g2)
vis_patch += cow.layout(design = np.array([[0,0,0,1,1,1], 

Displaying the image

Finally, we can display the arrangement using the .show method1. To save the arrangement on can use the .save method. = 11, height = 7)
/home/runner/work/cowpatch/cowpatch/src/cowpatch/ CowpatchWarning: Showing 11 x 7 inch image.


The .show method works slightly different inside jupyter notebooks versus from the command line. Inside jupyter notebook the image is displayed as an svg object. From the command line we present a png representation of the object using matplotlib.pyplot’s standard graphic presenter. Note the command line approach doesn’t update the image when the sizing of the display is changed(.