ggsave()¶Parameters dpi, w, h and unit can be used to configure export to a raster image with required physical metrics. Aspect ratio must be maintained manually between ggsize() and ggsave(). Please note that using these parameters will disable the scale parameter.
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
np.random.seed(12)
data = dict(
cond=np.repeat(['A', 'B'], 200),
rating=np.concatenate((np.random.normal(0, 1, 200), np.random.normal(1, 1.5, 200)))
)
p = ggplot(data, aes(x='rating', fill='cond')) + ggsize(800, 400) + \
geom_density(color='dark_green', alpha=.7) + scale_fill_brewer(type='seq') + \
theme(panel_grid_major_x='blank')
p
_ = ggsave(p, 'plot_ggsave.png')
ggsave()¶_ = ggsave(p, 'plot_ggsave_96dpi.png', w=8, h=4, unit='in', dpi=96)
_ = ggsave(p, 'plot_ggsave_300dpi.png', w=8, h=4, unit='in', dpi=300)
to_png()¶_ = p.to_png('plot_to_png_96dpi.png', w=8, h=4, unit='in', dpi=96)
_ = p.to_png('plot_to_png_300dpi.png', w=8, h=4, unit='in', dpi=300)
gggrid()¶g = gggrid([
p,
p + coord_flip()
]) + ggsize(1000, 300)
g
_ = ggsave(g, 'grid_ggsave_96dpi.png', w=10, h=3, unit='in', dpi=96)
_ = ggsave(g, 'grid_ggsave_300dpi.png', w=10, h=3, unit='in', dpi=300)