Back to Article
plot_spacer.ipynb
Download Notebook
In [1]:
from plotnine import ggplot, aes, geom_point, geom_boxplot, theme, element_rect
from plotnine.composition import plot_spacer
from plotnine.data import mtcars
In [2]:
p1 = ggplot(mtcars, aes("wt", "mpg")) + geom_point()
p2 = ggplot(mtcars, aes("wt", "disp")) + geom_point()
p3 = ggplot(mtcars, aes("factor(cyl)", "wt")) + geom_boxplot()

p1 | plot_spacer() | p2

In [3]:
p1 | (p2 / plot_spacer() / p3)

Change the color of the space.

In [4]:
p1 | plot_spacer("#FF000022") | p2

Which is the same as

In [5]:
p1 | (plot_spacer() + theme(plot_background=element_rect(fill="#FF000022"))) | p2