[Matplotlib-devel] (no subject)

Thomas Caswell tcaswell at gmail.com
Sun Jun 5 20:31:07 EDT 2016


Simply sub-classing any of those classes in your code would reasonable.

I am curious about what sort of extensions you are adding?  I think in many
cases writing functions that take in `Axes` (or `Figure` if that is the
right scope) objects and operate on them.

An example of a project that is sub-classing `Axes` is
https://github.com/scls19fr/windrose .

Tom

On Sun, Jun 5, 2016 at 5:16 PM Daniel McNeela <daniel.mcneela at gmail.com>
wrote:

> 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
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20160606/099cf503/attachment-0001.html>


More information about the Matplotlib-devel mailing list