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

Bases: Renderer

Abstract class for rendering visualizations using Matplotlib.

  • figure_id (int or None) – A figure id or None. None assumes we maintain the Matplotlib state machine and use plt.gcf().
  • new_figure (bool) – If True, it creates a new figure to render on.

Method for clearing the current figure.


Method for forcing the current figure to render. This is useful for the widgets animation.


Gets the figure specified by the combination of self.figure_id and self.new_figure. If self.figure_id == None then plt.gcf() is used. self.figure_id is also set to the correct id of the figure if a new figure is created.

Returns:figure (Matplotlib figure object) – The figure we will be rendering on.

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(filename, format='png', dpi=None, face_colour='w', edge_colour='w', orientation='portrait', paper_type='letter', transparent=False, pad_inches=0.1, overwrite=False)[source]

Method for saving the figure of the current figure_id to file.

  • filename (str or file-like object) – The string path or file-like object to save the figure at/into.
  • format (str) – The format to use. This must match the file path if the file path is a str.
  • dpi (int > 0 or None, optional) – The resolution in dots per inch.
  • face_colour (See Below, optional) –

    The face colour of the figure rectangle. Example options

    {``r``, ``g``, ``b``, ``c``, ``m``, ``k``, ``w``}
    ``(3, )`` `ndarray`
    `list` of len 3
  • edge_colour (See Below, optional) –

    The edge colour of the figure rectangle. Example options

    {``r``, ``g``, ``b``, ``c``, ``m``, ``k``, ``w``}
    ``(3, )`` `ndarray`
    `list` of len 3
  • orientation ({portrait, landscape}, optional) – The page orientation.
  • paper_type (See Below, optional) –

    The type of the paper. Example options

    {``letter``, ``legal``, ``executive``, ``ledger``,
     ``a0`` through ``a10``, ``b0` through ``b10``}
  • transparent (bool, optional) – If True, the axes patches will all be transparent; the figure patch will also be transparent unless face_colour and/or edge_colour are specified. This is useful, for example, for displaying a plot on top of a coloured background on a web page. The transparency of these patches will be restored to their original values upon exit of this function.
  • pad_inches (float, optional) – Amount of padding around the figure.
  • overwrite (bool, optional) – If True, the file will be overwritten if it already exists.

Method for saving the figure of the current figure_id to file using menpowidgets.base.save_matplotlib_figure widget.