GGBunch allows to show a collection of plots on one figure. Each plot in the collection can have arbitrary location and size. There is no automatic layout inside the bunch.
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
np.random.seed(42)
cov=[[1, 0],
[0, 1]]
x, y = np.random.multivariate_normal(mean=[0,0], cov=cov, size=400).T
data = dict(
x = x,
y = y
)
p = ggplot(data) + ggsize(600,200)
scatter = p + geom_point(aes('x', 'y'), color='black', alpha=.4)
scatter
histogram = p + geom_histogram(aes('x', y = '..count..'), fill='dark_magenta')
histogram
# Set scale X limits manually because of computed automatically
# the scale used by each plot would be slightly different
# and the stacked plots wouldn't be aligned.
scale_x = scale_x_continuous(limits=[-3.5, 3.5])
bunch = GGBunch()
bunch.add_plot(histogram + scale_x, 0, 0)
bunch.add_plot(scatter + scale_x, 0, 200)
bunch.show()
upper_theme = theme(axis_title_x='blank', axis_ticks_x='blank', axis_line='blank', \
panel_grid='blank')
lower_theme = theme(axis_text_x='blank', axis_ticks_x='blank', axis_line='blank')
bunch1 = GGBunch()
bunch1.add_plot(histogram + upper_theme + scale_x, 0, 0)
bunch1.add_plot(scatter + lower_theme + scale_x, 0, 200)
bunch1.show()
add_plot() method has two more (optional) parameters: width and height.
This values will override plot size earlier defined via ggsize() function.
bunch2 = GGBunch()
bunch2.add_plot(histogram + upper_theme + scale_x, 0, 0, 600, 100)
bunch2.add_plot(scatter + lower_theme + scale_x, 0, 100, 600, 300)
bunch2.show()