The margins around the plot and text elements are controlled by the plot_margin
parameter in theme()
and the margin
parameter in element_text()
respectively.
Now the parameters plot_margin
and margin
accept a number or a list of numbers.
It is acceptable to use None for any side; in this case, the default side value for this element will be used.
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
np.random.seed(42)
data = {'x': np.random.randint(10, size=100)}
p = ggplot(data, aes(x='x')) + \
geom_bar() + \
ggtitle("Bar Сhart") + \
theme_light() + \
theme(plot_background=element_rect(size = 4))
p
gggrid([
p + theme(plot_margin=40) + ggtitle("plot_margin=40 (all sides)"),
p + theme(plot_margin=[40,20]) + ggtitle("plot_margin=[40,20]\n(top/bottom, left/right)"),
p + theme(plot_margin=[40,20,10]) + ggtitle("plot_margin=[40,20,10]\n(top, left/right, bottom)"),
p + theme(plot_margin=[40,10,10,20]) + ggtitle("plot_margin=[40,10,10,20]\n(top, right, bottom, left)")
], ncol=2)
p + theme(plot_title = element_text(margin=[40,None]),
axis_title = element_text(margin=[20,20,None,None])) + \
ggtitle("plot_title=[40,None] -> top/bottom=40,\n" +
"axis_title=[20,20,None,None] -> top/right=20")