from plotnine import (
ggplot,
aes,
geom_point,
facet_grid,
labs,
guide_legend,
guides,
theme,
element_text,
element_line,
element_rect,
theme_set,
theme_void,
)from plotnine.data import mtcars
# We use theme_void as the base theme so that the modifications
# we make in the code are transparent in the output
theme_set(theme_void())
plotnine.theme
theme(=False,
complete=None,
axis_title_x=None,
axis_title_y=None,
axis_title=None,
legend_title=None,
legend_text_legend=None,
legend_text_colorbar=None,
legend_text=None,
plot_title=None,
plot_subtitle=None,
plot_caption=None,
strip_text_x=None,
strip_text_y=None,
strip_text=None,
title=None,
axis_text_x=None,
axis_text_y=None,
axis_text=None,
text=None,
axis_line_x=None,
axis_line_y=None,
axis_line=None,
axis_ticks_minor_x=None,
axis_ticks_minor_y=None,
axis_ticks_major_x=None,
axis_ticks_major_y=None,
axis_ticks_major=None,
axis_ticks_minor=None,
axis_ticks_x=None,
axis_ticks_y=None,
axis_ticks=None,
legend_ticks=None,
panel_grid_major_x=None,
panel_grid_major_y=None,
panel_grid_minor_x=None,
panel_grid_minor_y=None,
panel_grid_major=None,
panel_grid_minor=None,
panel_grid=None,
line=None,
legend_key=None,
legend_frame=None,
legend_background=None,
legend_box_background=None,
panel_background=None,
panel_border=None,
plot_background=None,
strip_background_x=None,
strip_background_y=None,
strip_background=None,
rect=None,
axis_ticks_length_major_x=None,
axis_ticks_length_major_y=None,
axis_ticks_length_major=None,
axis_ticks_length_minor_x=None,
axis_ticks_length_minor_y=None,
axis_ticks_length_minor=None,
axis_ticks_length=None,
axis_ticks_pad_major_x=None,
axis_ticks_pad_major_y=None,
axis_ticks_pad_major=None,
axis_ticks_pad_minor_x=None,
axis_ticks_pad_minor_y=None,
axis_ticks_pad_minor=None,
axis_ticks_pad=None,
panel_spacing_x=None,
panel_spacing_y=None,
panel_spacing=None,
plot_margin_left=None,
plot_margin_right=None,
plot_margin_top=None,
plot_margin_bottom=None,
plot_margin=None,
panel_ontop=None,
aspect_ratio=None,
dpi=None,
figure_size=None,
legend_box=None,
legend_box_margin=None,
legend_box_just=None,
legend_justification_right=None,
legend_justification_left=None,
legend_justification_top=None,
legend_justification_bottom=None,
legend_justification_inside=None,
legend_justification=None,
legend_direction=None,
legend_key_width=None,
legend_key_height=None,
legend_key_size=None,
legend_ticks_length=None,
legend_margin=None,
legend_box_spacing=None,
legend_spacing=None,
legend_position_inside=None,
legend_position=None,
legend_title_position=None,
legend_text_position=None,
legend_key_spacing_x=None,
legend_key_spacing_y=None,
legend_key_spacing=None,
strip_align_x=None,
strip_align_y=None,
strip_align=None,
svg_usefonts={}
kwargs )
Base class for themes
In general, only complete themes should subclass this class.
Parameters
complete : bool = False
-
Themes that are complete will override any existing themes. themes that are not complete (ie. partial) will add to or override specific elements of the current theme. e.g:
+ theme_xkcd() theme_gray()
will be completely determined by
theme_xkcd
, but:+ theme(axis_text_x=element_text(angle=45)) theme_gray()
will only modify the x-axis text.
kwargs = {}
-
kwargs are
themeables
. The themeables are elements that are subclasses ofthemeable
. Many themeables are defined using theme elements i.eelement_line
element_rect
element_text
These simply bind together all the aspects of a themeable that can be themed. See
themeable
.
Notes
When subclassing, make sure to call theme.__init__
. After which you can customise self._rcParams
within the __init__
method of the new theme. The rcParams
should not be modified after that.
Examples
Methods
Name | Description |
---|---|
add_theme | Add themes together |
apply | Apply this theme, then apply additional modifications in order. |
setup | Setup theme for applying |
to_retina | Return a retina-sized version of this theme |
add_theme
add_theme(other)
Add themes together
Subclasses should not override this method.
This will be called when adding two instances of class ‘theme’ together. A complete theme will annihilate any previous themes. Partial themes can be added together and can be added to a complete theme.
apply
apply()
Apply this theme, then apply additional modifications in order.
This method will be called once after plot has completed. Subclasses that override this method should make sure that the base class method is called.
setup
setup(plot)
Setup theme for applying
This method will be called when the figure and axes have been created but before any plotting or other artists have been added to the figure. This method gives the theme and the elements references to the figure and/or axes.
It also initialises where the artists to be themed will be stored.
to_retina
to_retina()
Return a retina-sized version of this theme
The result is a theme that has double the dpi.