deleting gray panels in Axes3D

Hi all,

I'm making a 3d plot using Axes3D (plot_surface) and I want to get rid of the 3d gray box that surrounds the object so that only the object shows up. Is there a way to do it? After creating my Axes3D instance, I can't find much else than methods to change the x,y,z labels and axis limits.

I found a hack using myAXINFO to change the color of each "panel" but the axis line still remains there.

Ideally, there would be methods to access the color, visibility, etc., of these elements. Maybe it's somewhere I can't find them...

Here's a code snippet derived from one of the website's examples:

···

#############
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
         linewidth=0, antialiased=False)
ax.set_zlim3d(-1.01, 1.01)

# The following makes the panels white, but the axis line remains there
myAXINFO = { 'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2), 'color': (1.0, 1.0, 1.0, 1.0, 1.0)}, 'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2), 'color': (1.0, 1.0, 1.0, 1.0, 1.0)}, 'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1), 'color': (1.0, 1.0, 1.0, 1.0, 1.0)} }
ax.w_zaxis._AXINFO = myAXINFO
ax.w_yaxis._AXINFO = myAXINFO
ax.w_xaxis._AXINFO = myAXINFO

plt.show()
#############

Thanks!

Rene

Rene,

Unfortunately, you have stumbled upon one of the ugliness of the mplot3d implementation. I am hoping to have more control available for the next release. But right now, there is no way to turn off the axes spines (because they aren’t implemented as spines). If you really want to dig into the source code, you could change the color argument to the Line2D call in the init3d() method in matplotlib/lib/mpl_toolkits/axis3d.py

I am sorry I can not be more helpful.
Ben Root

···

On Wed, Feb 23, 2011 at 4:19 PM, Rene Breton <superluminique@…287…> wrote:

Hi all,

I’m making a 3d plot using Axes3D (plot_surface) and I want to get rid

of the 3d gray box that surrounds the object so that only the object

shows up. Is there a way to do it? After creating my Axes3D instance, I

can’t find much else than methods to change the x,y,z labels and axis

limits.

I found a hack using myAXINFO to change the color of each “panel” but

the axis line still remains there.

Ideally, there would be methods to access the color, visibility, etc.,

of these elements. Maybe it’s somewhere I can’t find them…

Here’s a code snippet derived from one of the website’s examples:

#############

from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

from matplotlib.ticker import LinearLocator, FixedLocator,

FormatStrFormatter

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.gca(projection=‘3d’)

X = np.arange(-5, 5, 0.25)

Y = np.arange(-5, 5, 0.25)

X, Y = np.meshgrid(X, Y)

R = np.sqrt(X2 + Y2)

Z = np.sin®

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,

     linewidth=0, antialiased=False)

ax.set_zlim3d(-1.01, 1.01)

The following makes the panels white, but the axis line remains there

myAXINFO = { ‘x’: {‘i’: 0, ‘tickdir’: 1, ‘juggled’: (1, 0, 2), ‘color’:

(1.0, 1.0, 1.0, 1.0, 1.0)}, ‘y’: {‘i’: 1, ‘tickdir’: 0, ‘juggled’: (0,

1, 2), ‘color’: (1.0, 1.0, 1.0, 1.0, 1.0)}, ‘z’: {‘i’: 2, ‘tickdir’: 0,

‘juggled’: (0, 2, 1), ‘color’: (1.0, 1.0, 1.0, 1.0, 1.0)} }

ax.w_zaxis._AXINFO = myAXINFO

ax.w_yaxis._AXINFO = myAXINFO

ax.w_xaxis._AXINFO = myAXINFO

plt.show()

#############

Thanks!

Rene

Thanks much for the quick answer Ben!

At least now I know it doesn't exist, yet. I might dig into the source code to change the color as you suggest. As a workaround, maybe I will simply tweak the .ps output in Adobe Illustrator; should be easy enough to remove such thing.

By the way, I'm very glad you (and people) took over the mplot3d. I really think that 3D plotting was the number one missing thing in Matplotlib and Python more generally. (mayavi2 is way to complicated and clunky for what most people need)

If I may make another suggestion, besides getting more control over the axes spines, it would be to allow the axes rendering to "mix" multiple plot objects. Let's say one plots a sphere and a cylinder (like a rod) that goes through the sphere and get the part of the cylinder that lies inside the sphere to be hidden. Of course, I realize it might not be trivial to do, depending exactly how plots are rendered.

Cheers,

Rene

···

On 11-02-23 05:33 PM, Benjamin Root wrote:

On Wed, Feb 23, 2011 at 4:19 PM, Rene Breton <superluminique@…287… > <mailto:superluminique@…287…>> wrote:

    Hi all,

    I'm making a 3d plot using Axes3D (plot_surface) and I want to get rid
    of the 3d gray box that surrounds the object so that only the object
    shows up. Is there a way to do it? After creating my Axes3D instance, I
    can't find much else than methods to change the x,y,z labels and axis
    limits.

    I found a hack using myAXINFO to change the color of each "panel" but
    the axis line still remains there.

    Ideally, there would be methods to access the color, visibility, etc.,
    of these elements. Maybe it's somewhere I can't find them...

    Here's a code snippet derived from one of the website's examples:

    #############
    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib import cm
    from matplotlib.ticker import LinearLocator, FixedLocator,
    FormatStrFormatter
    import matplotlib.pyplot as plt
    import numpy as np

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    X = np.arange(-5, 5, 0.25)
    Y = np.arange(-5, 5, 0.25)
    X, Y = np.meshgrid(X, Y)
    R = np.sqrt(X**2 + Y**2)
    Z = np.sin(R)
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
             linewidth=0, antialiased=False)
    ax.set_zlim3d(-1.01, 1.01)

    # The following makes the panels white, but the axis line remains there
    myAXINFO = { 'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2), 'color':
    (1.0, 1.0, 1.0, 1.0, 1.0)}, 'y': {'i': 1, 'tickdir': 0, 'juggled': (0,
    1, 2), 'color': (1.0, 1.0, 1.0, 1.0, 1.0)}, 'z': {'i': 2, 'tickdir': 0,
    'juggled': (0, 2, 1), 'color': (1.0, 1.0, 1.0, 1.0, 1.0)} }
    ax.w_zaxis._AXINFO = myAXINFO
    ax.w_yaxis._AXINFO = myAXINFO
    ax.w_xaxis._AXINFO = myAXINFO

    plt.show()
    #############

    Thanks!

    Rene

Rene,

Unfortunately, you have stumbled upon one of the ugliness of the mplot3d
implementation. I am hoping to have more control available for the next
release. But right now, there is no way to turn off the axes spines
(because they aren't implemented as spines). If you really want to dig
into the source code, you could change the color argument to the Line2D
call in the init3d() method in matplotlib/lib/mpl_toolkits/axis3d.py

I am sorry I can not be more helpful.
Ben Root

Thanks much for the quick answer Ben!

At least now I know it doesn’t exist, yet. I might dig into the source

code to change the color as you suggest. As a workaround, maybe I will

simply tweak the .ps output in Adobe Illustrator; should be easy enough

to remove such thing.

Another issue may be the tickmarks, which are made separately in another segment of code.

By the way, I’m very glad you (and people) took over the mplot3d. I

really think that 3D plotting was the number one missing thing in

Matplotlib and Python more generally. (mayavi2 is way to complicated and

clunky for what most people need)

Thank you for your vote of confidence. This is exactly the intent of mplot3d, which is to allow for the possibility of basic 3d plotting features without the need to go “all-in” to a major 3d plotting system. We are still a long way from what I envision for mplot3d.

If I may make another suggestion, besides getting more control over the

axes spines, it would be to allow the axes rendering to “mix” multiple

plot objects. Let’s say one plots a sphere and a cylinder (like a rod)

that goes through the sphere and get the part of the cylinder that lies

inside the sphere to be hidden. Of course, I realize it might not be

trivial to do, depending exactly how plots are rendered.

You are not the first to request this, and you will not be the last. Unfortunately, it is an intractable problem that can never be completely solved by the 2d rendering framework employed by matplotlib. If/When matplotlib gains an opengl backend, this problem will be revisited.

Please do continue to feel free to continue commenting on mplot3d and how you think it can be better. And, as always, patches are welcome!

Ben Root

···

On Wed, Feb 23, 2011 at 4:52 PM, Rene Breton <superluminique@…287…> wrote: