lets_plot.theme¶
- lets_plot.theme(*, line=None, rect=None, text=None, title=None, axis=None, axis_ontop=None, axis_ontop_x=None, axis_ontop_y=None, axis_title=None, axis_title_x=None, axis_title_y=None, axis_text=None, axis_text_x=None, axis_text_y=None, axis_ticks=None, axis_ticks_x=None, axis_ticks_y=None, axis_ticks_length=None, axis_ticks_length_x=None, axis_ticks_length_y=None, axis_line=None, axis_line_x=None, axis_line_y=None, legend_background=None, legend_text=None, legend_title=None, legend_position=None, legend_justification=None, legend_direction=None, panel_background=None, panel_border=None, panel_grid=None, panel_grid_major=None, panel_grid_minor=None, panel_grid_major_x=None, panel_grid_minor_x=None, panel_grid_major_y=None, panel_grid_minor_y=None, plot_background=None, plot_title=None, plot_subtitle=None, plot_caption=None, strip_background=None, strip_text=None, axis_tooltip=None, axis_tooltip_x=None, axis_tooltip_y=None, axis_tooltip_text=None, axis_tooltip_text_x=None, axis_tooltip_text_y=None, tooltip=None, tooltip_text=None, tooltip_title_text=None)¶
Use theme() to modify individual components of a theme, allowing you to control all non-data components of the plot.
- Parameters
- linestr or dict
All line elements. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_line() to specify line parameters.
- rectstr or dict
All rectangular elements. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_rect() to specify rectangular element parameters.
- textstr or dict
All text elements. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify text parameters.
- titlestr or dict
All title elements: plot, axes, legends. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify title text parameters, inherited from text.
- axisstr or dict
All axis elements: lines, ticks, texts, titles. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_line() to specify axes parameters.
- axis_ontop, axis_ontop_x, axis_ontop_ybool, default=False
Option to place axis (lines, tickmarks and labels) over the data layers.
- axis_title, axis_title_x, axis_title_ystr or dict
Labels of axes. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify axes label parameters. axis_title_* inherits from axis_title which inherits from text.
- axis_text, axis_text_x, axis_text_ystr or dict
Tick labels along axes. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify all axes tick label parameters. axis_text_* inherits from axis_text which inherits from text.
- axis_ticks, axis_ticks_x, axis_ticks_ystr or dict
Tick marks along axes. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_line() to specify all tick mark parameters. axis_ticks_* inherits from axis_ticks which inherits from line.
- axis_ticks_length, axis_ticks_length_x, axis_ticks_length_yfloat
Length of tick marks in px.
- axis_line, axis_line_x, axis_line_ystr or dict
Lines along axes. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_line() to specify line parameters along all axes. axis_line_* inherits from axis_line which inherits from line.
- legend_backgroundstr or dict
Background of legend. Set ‘blank’ or result of element_blank() to draw nothing. Set element_rect() to specify legend background parameters, inherited from rect.
- legend_textstr or dict
Legend item labels. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify legend item label parameters, inherited from text.
- legend_titlestr or dict
Title of legend. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify legend title parameters, inherited from title.
- legend_position{‘none’, ‘left’, ‘right’, ‘bottom’, ‘top’} or list
The position of legends. To remove the plot legend, use the ‘none’ value. If parameter is a list, then it should be a two-element numeric vector, each value of float type between 0 and 1.
- legend_justificationstr or list
Anchor point for positioning legend. If parameter is a list, then it should be a two-element numeric vector. The pair [0, 0] corresponds to the bottom left corner, the pair [1, 1] corresponds to the top right. For string parameter the only possible value is ‘center’.
- legend_direction{‘horizontal’, ‘vertical’}
Layout of items in legends.
- panel_backgroundstr or dict
Background of plotting area. Set ‘blank’ or result of element_blank() to draw nothing. Set element_rect() to specify plotting area background parameters, inherited from rect.
- panel_borderstr or dict
Border around plotting area. Set ‘blank’ or result of element_blank() to draw nothing. Set element_rect() to specify border parameters, inherited from rect.
- panel_grid, panel_grid_major, panel_grid_minor, panel_grid_major_x, panel_grid_major_y, panel_grid_minor_x, panel_grid_minor_ystr or dict
Grid lines. Specify major grid lines or minor grid lines separately if needed. Set ‘blank’ or result of element_blank() to draw nothing. Set element_line() to specify grid line parameters. panel_grid_*_* inherits from panel_grid_* which inherits from panel_grid, which in turn inherits from line.
- plot_backgroundstr or dict
Background of the entire plot. Set ‘blank’ or result of element_blank() to draw nothing. Set element_rect() to specify plot background parameters, inherited from rect.
- plot_titlestr or dict
Plot title. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify plot title parameters, inherited from title.
- plot_subtitlestr or dict
Plot subtitle. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify plot subtitle parameters, inherited from plot_title or title.
- plot_captionstr or dict
Plot caption. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify plot caption parameters, inherited from title.
- strip_backgroundstr or dict
Background of facet labels. Set ‘blank’ or result of element_blank() to draw nothing. Set element_rect() to specify facet label background parameters, inherited from rect.
- strip_textstr or dict
Facet labels. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify facet label parameters, inherited from text.
- axis_tooltip, axis_tooltip_x, axis_tooltip_ystr or dict
Axes tooltips. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_rect() to specify axes tooltip parameters. axis_tooltip_* inherits from axis_tooltip which inherits from rect.
- axis_tooltip_text, axis_tooltip_text_x, axis_tooltip_text_ystr or dict
Text in axes tooltips. Set ‘blank’ or result of element_blank() to draw nothing and assign no space. Set element_text() to specify axes text tooltip parameters. axis_tooltip_text_* inherits from axis_tooltip_text which inherits from tooltip_text.
- tooltipstr or dict
General tooltip. Set element_rect() to specify tooltip rectangular parameters, inherited from rect.
- tooltip_textstr or dict
Text in general tooltip. Set element_text() to specify tooltip text parameters.
- tooltip_title_text: str or dict
Tooltip title text. Set element_text() to specify tooltip title parameters, inherited from tooltip_text. Bold by default.
- Returns
- ——-
- `FeatureSpec`
Theme specification.
Examples
1import numpy as np 2from lets_plot import * 3LetsPlot.setup_html() 4n = 100 5np.random.seed(42) 6x = np.random.normal(size=n) 7c = np.random.choice(['a', 'b', 'c'], size=n) 8ggplot({'x': x, 'class': c}, aes('x')) + \ 9 geom_density(aes(color='class'), size=2) + \ 10 ggtitle('Density of classes') + \ 11 theme(axis_line=element_line(size=4), \ 12 axis_ticks_length=10, \ 13 axis_title_y='blank', \ 14 legend_position=[1, 1], legend_justification=[1, 1], \ 15 panel_background=element_rect(color='black', fill='#eeeeee', size=2), \ 16 panel_grid=element_line(color='black', size=1))
1import numpy as np 2from lets_plot import * 3LetsPlot.setup_html() 4n = 1000 5np.random.seed(42) 6p = np.random.uniform(size=7) 7x = np.random.choice(range(p.size), p=p/p.sum(), size=n) 8c = np.random.choice(['a', 'b', 'c'], p=[.5, .3, .2], size=n) 9ggplot({'x': x, 'class': c}) + \ 10 geom_bar(aes('x', fill='x')) + \ 11 scale_y_continuous(breaks=list(range(0, 151, 25))) + \ 12 scale_fill_discrete() + \ 13 facet_grid(y='class') + \ 14 theme(axis_line_x='blank', \ 15 axis_ticks=element_line(color='white'), \ 16 panel_grid_major_x='blank', \ 17 strip_background=element_rect(color='black', fill='white'), \ 18 axis_tooltip=element_rect(color='black', fill='white'), \ 19 legend_position='top')