#!/usr/bin/env python # coding: utf-8 # # Legend Spacing and Margins # # New parameters in `theme()` to customize the legend spacing and margins: # # # - `legend_box` - arrangement of multiple legends ("horizontal" or "vertical"); # - `legend_box_just` - justification of each legend within the overall bounding box ("top", "bottom", "left", "right", "center"); # - `legend_box_spacing` - spacing between plotting area and legend box; # # - `legend_margin` - margin around each legend; # - `legend_spacing` - spacing between legends, `legend_spacing_x`/`legend_spacing_y` - in the horizontal/vertical direction. # # # In[1]: from IPython.display import Image display(Image('images/theme_legend_scheme.png')) # In[2]: import pandas as pd from lets_plot import * # In[3]: LetsPlot.setup_html() # In[4]: mpg = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv") mpg.head(3) # In[5]: p = ggplot(mpg, aes('displ', 'cty', )) + \ geom_point(aes(fill='drv', size='hwy'), shape=21) + \ scale_size(range=[1, 10], breaks=[15, 30, 40]) + \ theme(legend_position='bottom', legend_background=element_rect(size=1)) p # #### `legend_margin` # In[6]: p + theme(legend_margin=[10, 20]) # #### `legend_box` # In[7]: p + theme(legend_box='horizontal') # #### `legend_box_just` # In[8]: p + theme(legend_box_just='center') # #### `legend_box_spacing` # In[9]: p + theme(legend_box='horizontal', legend_box_spacing=50) # #### `legend_spacing` # In[10]: p + theme(legend_box='horizontal', legend_spacing_x=50)