Compositor¶
The role of the Compositor is, from a given list of DataPoint, to draw a kind of mosaic, representing the different
tiles with their respective annotations.
In some ways, the Compositor is customizable. Different layouts of the mosaic can be built, depending on the use cases:
simple layout: the tiles will be placed following each others, mapping a rectangular grid. The number of columns of the final mosaic can be fixed.
adaptive layout: very similar with the simple layout, except that the last row of the mosaic is centered.
2D layout: in the case where a 2D array-like of
DataPointis given to theCompositor, each line of the mosaic will correspond to a row of that array (the row being generally of different lengths).
Moreover, you can decorate your final composition by adding a title on top of it, and a legend (cf. LegendPainter).
The actual compositor API is exposed here.
-
class
plums.plot.engine.compositor.CompositorBase(data_points, color_engine_interface)[source]¶ Bases:
abc.ABCAn abstract class that represents the minimum interface a Compositor needs.
- Parameters
data_points (array-like) – Two formats are allowed: a 2D array-like of
DataPoint-like collection ofTileandRecordCollectionto be drawn. Each line of the 2D array-like is expected to correspond to a line layout in the final mosaic cell. Or a 1D array-like ofDataPoint. In that case, the data points will be placed side by side, forming a mosaic of tiles, with rows of same length.color_engine_interface (dict) – A mapping of categories with colors/colormaps to draw.
- Raises
AttributeError – When
data_pointsis not a list/tuple or a nested list/tuple of data points.
-
abstract
plot(n_cols=20, margins=(5, 5), background_color=(127, 127, 120), title=None, title_size=25, center=True, **kwargs)[source]¶ Create a mosaic of the different accumulated datapoints, with a legend to identify colors meaning.
- Parameters
n_cols (int) – Optional. Defaults to
20. Number of data points per line to not exceed (if 1D array-like ofDataPoint).margins (tuple) – Optional. Defaults to
(5, 5). Margin to use between each image of the mosaic.background_color (tuple) – Optional. Defaults to
(127, 127, 120). Background color to use for the mosaic.title (str) – Optional. Defaults to
None. A title to place on top of the mosaic.title_size (int) – Optional. Defaults to
25. Font size of the title (in pixels).center (bool) – Optional. Defaults to
True. Center the last line of data points. (if 1D array-like ofDataPoint).kwargs (dict) – These parameters are passed on to the constructors of the
Painterand theLegendPainter.
- Raises
NotImplementedError – Since it is an abstract method, you have to implement it.
-
class
plums.plot.engine.compositor.Compositor(data_points, color_engine_interface)[source]¶ Bases:
plums.plot.engine.compositor.CompositorBaseA class that draws a complete mosaic of the given data points, with optionally a title and a meaningful legend.
The
Compositoraims to produce a fashionable way of visualising severalDataPointside-to-side. If a flattened list of data points is provided, the data points will be placed in a successive way, filling a grid (cfSimpleImagePositionGeneratororAdaptiveImagePositionGenerator). If a 2D array-like of data points is given, we produce as many lines in the final mosaic as the length of the provided list. The lines may be of different sizes, the items are centered (cfLayoutImagePositionGenerator). The size of the mosaic will just adapt, depending on the chosen layout.- Parameters
data_points (array-like) – Two formats are allowed: a 2D array-like of
DataPoint-like collection ofTileandRecordCollectionto be drawn. Each line of the 2D array-like is expected to correspond to a line layout in the final mosaic cell. Or a 1D array-like ofDataPoint. In that case, the data points will be placed side by side, forming a mosaic of tiles, with rows of same length.color_engine_interface (dict) – A mapping of categories with
Color/ColorMapto draw.
- Raises
AttributeError – When
data_pointsis not a list/tuple or a nested list/tuple of data points.
-
MODE= 'RGBA'¶
-
plot(n_cols=20, margins=(5, 5), background_color=(127, 127, 120), title=None, title_size=25, center=True, **kwargs)[source]¶ Create a mosaic of the different accumulated data points, with a legend to identify colors meaning.
- Parameters
n_cols (int) – Optional. Defaults to
20. Number of data points per line to not exceed (if 1D array-like ofDataPoint).margins (tuple) – Optional. Defaults to
(5, 5). Margin to use between each image of the mosaic.background_color (tuple) – Optional. Defaults to
(127, 127, 120). Background color to use for the mosaic.title (str) – Optional. Defaults to
None. A title to place on top of the mosaic.title_size (int) – Optional. Defaults to
25. Font size of the title (in pixels).center (bool) – Optional. Defaults to
True. Center the last line of data points. (if 1D array-like ofDataPoint).kwargs (dict) – These parameters are passed on to the constructors of the
Painterand theLegendPainter.
- Returns
The final mosaic containing the painted images, a legend, and optionally a title.
- Return type
Image