plotnine.themes.themeable.themeable

class plotnine.themes.themeable.themeable(theme_element: Any = None)[source]

Bases: object

Abstract class of things that can be themed.

Every subclass of themeable is stored in a dict at themeable.register with the name of the subclass as the key.

It is the base of a class hierarchy that uses inheritance in a non-traditional manner. In the textbook use of class inheritance, superclasses are general and subclasses are specializations. In some since the hierarchy used here is the opposite in that superclasses are more specific than subclasses.

It is probably better to think if this hierarchy of leveraging Python's multiple inheritance to implement composition. For example the axis_title themeable is composed of the x_axis_title and the y_axis_title. We are just using multiple inheritance to specify this composition.

When implementing a new themeable based on the ggplot2 documentation, it is important to keep this in mind and reverse the order of the "inherits from" in the documentation.

For example, to implement,

  • axis_title_x - x axis label (element_text; inherits from axis_title)

  • axis_title_y - y axis label (element_text; inherits from axis_title)

You would have this implementation:

class axis_title_x(themeable):
    ...

class axis_title_y(themeable):
    ...

class axis_title(axis_title_x, axis_title_y):
    ...

If the superclasses fully implement the subclass, the body of the subclass should be "pass". Python(__mro__) will do the right thing.

When a method does require implementation, call super() then add the themeable's implementation to the axes.

Notes

A user should never create instances of class themeable or subclasses of it.