How do I ensure that my matplotlib axes are of a custom class?
I have a custom figure class and would like to ensure that all of the axes associated with it, whether created with subplots() or twinx() , etc. have custom behaviors. Right now I accomplish this by binding new methods to each axis after it has been created, e.g. by using import types def my_ax_method(ax, test): print('{0} is doing something new as a {1}.'.format(ax, test)) class MyFigure(matplotlib.figure.Figure): def __init__(self, **kwargs): super(MyFigure, self).__init__(**kwargs) axes_a = None axes_b = None axes_c = None def setup_axes(self, ax): self.axes_a = ax self.axes_b = self.axes_a