How can I remove the axes in an Axes3D class?

后端 未结 1 1313
情书的邮戳
情书的邮戳 2021-01-18 01:56

I am using mplot3d like this:

fig = plt.figure(figsize=(14,10))

ax = Axes3D(fig,azim=azimuth,elev=elevation)

ax.grid(on=False)

# Additional axes

xspan =          


        
相关标签:
1条回答
  • 2021-01-18 02:13

    If I understand your question correctly, all you need to do is call ax.axis("off") or equivalently, ax.set_axis_off().

    Just to make sure we're on the same page, your example code might produce something like this (if it could be executed as you posted it...):

    alt text

    While you want something like this: alt text

    Here's the code to generate the example below, for future reference:

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    
    fig = plt.figure()
    ax = Axes3D(fig)
    
    # Draw x, y, and z axis markers in the same way you were in
    # the code snippet in your question...
    xspan, yspan, zspan = 3 * [np.linspace(0,60,20)]
    zero = np.zeros_like(xspan)
    
    ax.plot3D(xspan, zero, zero,'k--')
    ax.plot3D(zero, yspan, zero,'k--')
    ax.plot3D(zero, zero, zspan,'k--')
    
    ax.text(xspan.max() + 10, .5, .5, "x", color='red')
    ax.text(.5, yspan.max() + 10, .5, "y", color='red')
    ax.text(.5, .5, zspan.max() + 10, "z", color='red')
    
    # Generate and plot some random data...
    ndata = 10
    x = np.random.uniform(xspan.min(), xspan.max(), ndata)
    y = np.random.uniform(yspan.min(), yspan.max(), ndata)
    z = np.random.uniform(zspan.min(), zspan.max(), ndata)
    c = np.random.random(ndata)
    
    ax.scatter(x, y, z, c=c, marker='o', s=20)
    
    # This line is the only difference between the two plots above!
    ax.axis("off")
    
    plt.show()
    
    0 讨论(0)
提交回复
热议问题