[Matplotlib-devel] (no subject)

Daniel McNeela daniel.mcneela at gmail.com
Sun Jun 5 22:37:35 EDT 2016


Basically I'm adding a "layer" construct to the Axes model that allows
users to define groups of Matplotlib artists that can be manipulated,
hidden, displayed, styled, etc. in tandem without affecting those artists
which are on other layers. It's sort of analogous to the way in which
layers work in Photoshop.

The issue with simply subclassing the Matplotlib Axes is that I want my
subclass to fully integrate with pyplot and other modules. For example, if
a user has my module imported and runs

>>> fig = plt.figure()
>>> subplot = plt.subplot(111)

I'd like for subplot to be an instance of my subclassed Axes rather than of
the default one provided by Matplotlib.

On Sun, Jun 5, 2016 at 5:31 PM, Thomas Caswell <tcaswell at gmail.com> wrote:

> 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/20160605/6622ff79/attachment.html>


More information about the Matplotlib-devel mailing list