Version 3.1.2
matplotlib

Related Topics

Custom Figure ClassΒΆ

You can pass a custom Figure constructor to figure if you want to derive from the default Figure. This simple example creates a figure with a figure title.

Traceback (most recent call last):
  File "/build/matplotlib-mO9dyQ/matplotlib-3.1.2/examples/subplots_axes_and_figures/custom_figure_class.py", line 1
    ===================
    ^
SyntaxError: invalid syntax
===================
Custom Figure Class
===================

You can pass a custom Figure constructor to figure if you want to derive from
the default Figure.  This simple example creates a figure with a figure title.
"""

import matplotlib.pyplot as plt
from matplotlib.figure import Figure


class MyFigure(Figure):
    def __init__(self, *args, figtitle='hi mom', **kwargs):
        """
        custom kwarg figtitle is a figure title
        """
        super().__init__(*args, **kwargs)
        self.text(0.5, 0.95, figtitle, ha='center')


fig = plt.figure(FigureClass=MyFigure, figtitle='my title')
ax = fig.subplots()
ax.plot([1, 2, 3])

plt.show()

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery