Skip to content

plot_spacer in nested compositions interferes with alignment and figure size #959

@ilia-kats

Description

@ilia-kats

Consider this example (slightly modified from the docs):

from plotnine import ggplot, aes, geom_point, geom_boxplot, theme, element_rect
from plotnine.composition import plot_spacer, Beside, Stack
from plotnine.data import mtcars

p1 = ggplot(mtcars, aes("wt", "mpg")) + geom_point()

p = Stack([Beside([p1, p1, p1]), Beside([p1, p1, plot_spacer()])])
p + theme(figure_size=(10, 10))

This results in
Image
where the figure_size is completely ignored (not really visible here in the issue, but evident in a notebook when trying different figure sizes).

On the other hand, getting rid of plot_spacer restores correct alignment and figure sizing:

p = Stack([Beside([p1, p1, p1]), Beside([p1, p1])])
p + theme(figure_size=(10, 10))
Image
p = Stack([Beside([p1, p1, p1]), Beside([p1, p1, p1])])
p + theme(figure_size=(10, 10))
Image

This is on plotnine 0.15.0.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions