subplotting 3d figures

Hello all,

I have always been a bit troubled with how Axes3D object is a bit of a 2nd-class citizen in matplotlib. In particular, it is very common to create a new axes using .add_subplot() or .gca(), but you can’t do that with Axes3D. You also can’t create subplots of 3d figures, you have to create multiple figures with single 3d plots in them.

My examination off the code have not revealed anything that prevents this from happening. Currently, the gca() and add_subplot() functions accept a kwarg of ‘projection’ which allows one to specify the name of a registered axes object. Currently axes.Axes, polar and a few others are registered, with axes.Axes being default.

I have found that 3 lines of code in the axes3d module to have it add the Axes3D class to the registry. Using a name of ‘3d’, one can specify the projection to gain a Axes3d object. Note, you will still have to import the Axes3D object as usual. Attached is a patch for axes3d.py and a file that could be added to mpl_examples/. Give it a shot and let me know how it works for you!

Enjoy!
Ben Root

P.S. - Can you just imagine subplots of animated 3d plots? wink… wink…

Axes3DSubplot.patch (754 Bytes)

subplot3d_demo.py (872 Bytes)

Just re-pinging to see if there is any interest in this patch.

Ben Root

···

On Sat, Jul 3, 2010 at 1:51 AM, Benjamin Root <ben.v.root@…149…> wrote:

Hello all,

I have always been a bit troubled with how Axes3D object is a bit of a 2nd-class citizen in matplotlib. In particular, it is very common to create a new axes using .add_subplot() or .gca(), but you can’t do that with Axes3D. You also can’t create subplots of 3d figures, you have to create multiple figures with single 3d plots in them.

My examination off the code have not revealed anything that prevents this from happening. Currently, the gca() and add_subplot() functions accept a kwarg of ‘projection’ which allows one to specify the name of a registered axes object. Currently axes.Axes, polar and a few others are registered, with axes.Axes being default.

I have found that 3 lines of code in the axes3d module to have it add the Axes3D class to the registry. Using a name of ‘3d’, one can specify the projection to gain a Axes3d object. Note, you will still have to import the Axes3D object as usual. Attached is a patch for axes3d.py and a file that could be added to mpl_examples/. Give it a shot and let me know how it works for you!

Enjoy!
Ben Root

P.S. - Can you just imagine subplots of animated 3d plots? wink… wink…

Hello all,

I have always been a bit troubled with how Axes3D object is a bit of a
2nd-class citizen in matplotlib. In particular, it is very common to create
a new axes using .add_subplot() or .gca(), but you can't do that with
Axes3D. You also can't create subplots of 3d figures, you have to create
multiple figures with single 3d plots in them.

My examination off the code have not revealed anything that prevents this
from happening. Currently, the gca() and add_subplot() functions accept a
kwarg of 'projection' which allows one to specify the name of a registered
axes object. Currently axes.Axes, polar and a few others are registered,
with axes.Axes being default.

I have found that 3 lines of code in the axes3d module to have it add the
Axes3D class to the registry. Using a name of '3d', one can specify the
projection to gain a Axes3d object. Note, you will still have to import the
Axes3D object as usual. Attached is a patch for axes3d.py and a file that
could be added to mpl_examples/. Give it a shot and let me know how it
works for you!

Enjoy!
Ben Root

Definitely interested. Thanks for the re-ping. Reinier is busy of
late so hasn't been able to get to the 3D stuff. Damned Germans and
their endless vacations -- actually my wife is German currently on an
endless vacation so shouldn't complain :slight_smile:

I am not a 3D user currently and was not even aware of the "one axes"
limitation you describe. So would this also prevent mixing 2D and 3D
in the same figure (in the trunk before your patch)? This looks like
a major and unobtrusive improvement. I tested it and it looks good.
Committed to 8497.

Perhaps you can update doc/mpl_toolkits/mplot3d/tutorial.rst showing
how to use the projection kwarg to mix 2D w/ 3D or place multiple 3D
plots in one figure.

If you'd like svn commit rights, send me your sf id.

P.S. - Can you just imagine subplots of animated 3d plots? wink... wink...

Damn, better get a new computer. I am doing my development currently
on a linux install running on a laptop under Sun VirtualBox. Even
typing an email can be painfully slow. Multiple animated mpl subplots
would definitely bring this box to it's knees. Well, technically,
it's already on its knees.

JDH

···

On Sat, Jul 3, 2010 at 1:51 AM, Benjamin Root <ben.v.root@...149...> wrote:

No problem. I am glad that it is useful. Yes, you can have a figure with a mix of 2D subplots and 3D subplots. I will make sure I include an example of that as well. I will look into updating the rst file, and also the current batch of examples to use the new approach.

I am honored you would offer me commit rights. I will contact you off list for more information.

About the animations, I do have a prototype of it, and it works even on my EeePC, however Ryan May and I are still working out some issues (particularly with rotating and zooming).

Thanks,
Ben Root

···

On Mon, Jul 5, 2010 at 6:18 PM, John Hunter <jdh2358@…149…> wrote:

On Sat, Jul 3, 2010 at 1:51 AM, Benjamin Root <ben.v.root@…149…> wrote:

Hello all,

I have always been a bit troubled with how Axes3D object is a bit of a

2nd-class citizen in matplotlib. In particular, it is very common to create

a new axes using .add_subplot() or .gca(), but you can’t do that with

Axes3D. You also can’t create subplots of 3d figures, you have to create

multiple figures with single 3d plots in them.

My examination off the code have not revealed anything that prevents this

from happening. Currently, the gca() and add_subplot() functions accept a

kwarg of ‘projection’ which allows one to specify the name of a registered

axes object. Currently axes.Axes, polar and a few others are registered,

with axes.Axes being default.

I have found that 3 lines of code in the axes3d module to have it add the

Axes3D class to the registry. Using a name of ‘3d’, one can specify the

projection to gain a Axes3d object. Note, you will still have to import the

Axes3D object as usual. Attached is a patch for axes3d.py and a file that

could be added to mpl_examples/. Give it a shot and let me know how it

works for you!

Enjoy!

Ben Root

Definitely interested. Thanks for the re-ping. Reinier is busy of

late so hasn’t been able to get to the 3D stuff. Damned Germans and

their endless vacations – actually my wife is German currently on an

endless vacation so shouldn’t complain :slight_smile:

I am not a 3D user currently and was not even aware of the “one axes”

limitation you describe. So would this also prevent mixing 2D and 3D

in the same figure (in the trunk before your patch)? This looks like

a major and unobtrusive improvement. I tested it and it looks good.

Committed to 8497.

Perhaps you can update doc/mpl_toolkits/mplot3d/tutorial.rst showing

how to use the projection kwarg to mix 2D w/ 3D or place multiple 3D

plots in one figure.

If you’d like svn commit rights, send me your sf id.

P.S. - Can you just imagine subplots of animated 3d plots? wink… wink…

Damn, better get a new computer. I am doing my development currently

on a linux install running on a laptop under Sun VirtualBox. Even

typing an email can be painfully slow. Multiple animated mpl subplots

would definitely bring this box to it’s knees. Well, technically,

it’s already on its knees.

JDH