[Matplotlib-devel] (no subject)
Daniel McNeela
daniel.mcneela at gmail.com
Sun Jun 5 17:15:48 EDT 2016
Hi All,
I'm currently developing a Python package built on top of Matplotlib, and
I'd like to add custom functionality to the Axes class while still
retaining all of the default Matplotlib syntax and commands. To do this,
I'd like to subclass matplotlib.axes.Axes (or possibly
matplotlib.axes._base._AxesBase) and add additional class attributes and
methods. Ideally, I'd like to do this without forking Matplotlib and
directly editing the source so as to maintain compatibility with future
Matplotlib releases. I see that in pyplot.py, calls to figure() accept an
optional FigureClass argument which I could use to pass a custom subclass
of Figure. I was thinking I could subclass Figure such that the subclass
overrides methods such as Figure.add_subplot() by calling the superclass's
method and passing my custom Axes subclass in as an optional argument. But
I'm not sure which methods I'd have to override, or how deep the rabbit
hole goes, as Axes objects seem to be generated in a number of places
throughout the Matplotlib source.
If anyone who is familiar with the code base might be able to suggest a
simple way in which I could accomplish this desired behavior, I would
greatly appreciate it! Right now, I'm adding the desired functionality via
a function that accepts Matplotlib Axes instances and binds custom
attributes/methods to these instances via Python's type.MethodType, but
this seems like a rather clunky and un-Pythonic approach to building what
will likely be an extensive application.
Thank you in advance for your help!
Best,
Daniel McNeela
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20160605/daa6517a/attachment.html>
More information about the Matplotlib-devel
mailing list