axes_class in add_subplot()?

Hi,

I sometimes use a custom Axes class, and want to use it with
add_subplot() command.
As a matter of fact, it IS possible with current version of matplotlib
but it seems a bit inconvenient to me.
Here is what I do.

class MyAxes(maxes.Axes):
    name="myaxes"

Sorry, I accidentally sent an incomplete email.
here is a complete one.

I sometimes use a custom Axes class, and want to use it with
add_subplot() command.
As a matter of fact, it IS possible with current version of matplotlib
but it seems a bit inconvenient to me.
Here is what I may do.

  import matplotlib.axes as maxes

  class MyAxes(maxes.Axes):
   name="myaxes"
    # some definitions

  import matplotlib.projections
  matplotlib.projections.register_projection(MyAxes)

  F = figure()
  ax = F.add_subplot(1,2,2, projection="myaxes")

But it would much better if I can simply do something like

  class MyAxes(maxes.Axes):
    # some definitions

  F = figure()
  ax = F.add_subplot(1,2,2, axes_class=MyAxes)

It seems rather straight forward to implement "axes_class" keyword in
add_subplot() and I may make a patch for it.
So, how does others think?

Regards,

-JJ

Seems totally reasonable an we'd be happy to accept a patch.

Thanks,
JDH

···

On Mon, Jun 30, 2008 at 2:31 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

It seems rather straight forward to implement "axes_class" keyword in
add_subplot() and I may make a patch for it.
So, how does others think?

Sounds ok to me. One thing to clarify though -- what to do if both "projection" and "axes_class" are provided? Throw an exception?

I have a small problem with the name "axes_class" because it is very non-obvious that it corresponds to "projection". Perhaps we should either 1) overload projection to take a class as well as strings, or 2) use "projection_class" instead of "axes_class". I think I prefer 1) though I'm wary of overloading in Python in general.

Cheers,
Mike

John Hunter wrote:

···

On Mon, Jun 30, 2008 at 2:31 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

It seems rather straight forward to implement "axes_class" keyword in
add_subplot() and I may make a patch for it.
So, how does others think?
    
Seems totally reasonable an we'd be happy to accept a patch.

Thanks,
JDH

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I picked "axes_class" because this is what is used in
"subplot_class_factory" function.
I rather prefer "axes_class" because, IMO, subclassing of Axes is not
only for a new projection.
For example, I have a simple subclass of Axes where I have
"baseline"-aligned x-ticklabels (instead of "top" align). Also, from
available options

  from matplotlib.projection import AitoffAxes

  1) f.add_subplot(1,2,1, projection=AitoffAxes)
  2) f.add_subplot(1,2,1, projection_class=AitoffAxes)
  3) f.add_subplot(1,2,1, axes_class=AitoffAxes)

I think option 3 makes a slightly more sense.

My patch (which is attached) if for option 3 and simply adds
"axes_class" keyword. It raises an Exception if "projection" is
supplied or polar=True. But feel free to modify or give me
suggestions. If others prefer option 1 or 2, I'll make a subsequent
change for it.

Regards,

-JJ

add_subplot_with_axes_clases.diff (2.73 KB)

···

On Tue, Jul 1, 2008 at 7:51 AM, Michael Droettboom <mdroe@...31...> wrote:

Sounds ok to me. One thing to clarify though -- what to do if both
"projection" and "axes_class" are provided? Throw an exception?

I have a small problem with the name "axes_class" because it is very
non-obvious that it corresponds to "projection". Perhaps we should either
1) overload projection to take a class as well as strings, or 2) use
"projection_class" instead of "axes_class". I think I prefer 1) though I'm
wary of overloading in Python in general.

Cheers,
Mike

John Hunter wrote:

On Mon, Jun 30, 2008 at 2:31 PM, Jae-Joon Lee <lee.j.joon@...149...> >> wrote:

It seems rather straight forward to implement "axes_class" keyword in
add_subplot() and I may make a patch for it.
So, how does others think?

Seems totally reasonable an we'd be happy to accept a patch.

Thanks,
JDH

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA