Renderer

class menpo.visualize.Renderer(figure_id, new_figure)[source]

Bases: object

Abstract class for rendering visualizations. Framework specific implementations of these classes are made in order to separate implementation cleanly from the rest of the code.

It is assumed that the renderers follow some form of stateful pattern for rendering to Figures. Therefore, the major interface for rendering involves providing a figure_id or a bool about whether a new figure should be used. If neither are provided then the default state of the rendering engine is assumed to be maintained.

Providing both a figure_id and new_figure == True is not a valid state.

Parameters:
  • figure_id (object) – A figure id. Could be any valid object that identifies a figure in a given framework (str, int, float, etc.).
  • new_figure (bool) – Whether the rendering engine should create a new figure.
Raises:

ValueError – It is not valid to provide a figure id AND request a new figure to be rendered on.

get_figure()[source]

Abstract method for getting the correct figure to render on. Should also set the correct figure_id for the figure.

Returns:figure (object) – The figure object that the renderer will render on.
render(**kwargs)[source]

Abstract method to be overridden by the renderer. This will implement the actual rendering code for a given object class.

Parameters:kwargs (dict) – Passed through to specific rendering engine.
Returns:viewer (Renderer) – Pointer to self.
save_figure(**kwargs)[source]

Abstract method for saving the figure of the current figure_id to file. It will implement the actual saving code for a given object class.

Parameters:kwargs (dict) – Options to be set when saving the figure to file.