5

I would like to remove the borders from my 3D scene as described below. Any idea how to do that?

enter image description here

Here the code to generate the current scene:

import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Create figure plt.style.use('dark_background') # Dark theme fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Make panes transparent ax.xaxis.pane.fill = False # Left pane ax.yaxis.pane.fill = False # Right pane # Remove grid lines ax.grid(False) # Remove tick labels ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) # Print chart file_path = 'charts/3d.png' fig.savefig(file_path, bbox_inches='tight', pad_inches=0.05, transparent=True) 

3 Answers 3

7

I usually set the alpha channel to 0 for spines and panes, and finally I remove the ticks:

import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Create figure plt.style.use('dark_background') # Dark theme fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Make panes transparent ax.xaxis.pane.fill = False # Left pane ax.yaxis.pane.fill = False # Right pane # Remove grid lines ax.grid(False) # Remove tick labels ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) # Transparent spines ax.w_xaxis.line.set_color((1.0, 1.0, 1.0, 0.0)) ax.w_yaxis.line.set_color((1.0, 1.0, 1.0, 0.0)) ax.w_zaxis.line.set_color((1.0, 1.0, 1.0, 0.0)) # Transparent panes ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) # No ticks ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) 
Sign up to request clarification or add additional context in comments.

3 Comments

You're a magician! I'm not sure why someone voted down on your answer but it worked like a charm for me. Thank you so much!
glad to help :)
I have one more question here if you have any clue :p stackoverflow.com/questions/59890982/… I'll continue to investigate on my side
2

Try to add the following parameter when creating the figure

plt.figure(frameon=False)

EDIT: The lines containing comments are the ones i added/changed

import matplotlib.pyplot as plt import numpy as np # Imported numpy for random data from mpl_toolkits.mplot3d import Axes3D plt.style.use('dark_background') fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.xaxis.pane.fill = False ax.yaxis.pane.fill = False ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) # Remove the axis plt.axis('off') # Random data to illustrate zdata = 15 * np.random.random(100) xdata = np.sin(zdata) + 0.1 * np.random.randn(100) ydata = np.cos(zdata) + 0.1 * np.random.randn(100) ax.scatter3D(xdata, ydata, zdata, c=zdata, cmap='Greens') # Print chart (savefig overwrites some styling configs, better this way) with open('3d.png', 'wb') as outfile: fig.canvas.print_png(outfile) 

5 Comments

Thank you Hugo, it does not seem to work. Could you please illustrate how you would add it in the complete code snippet above? Maybe I'm doing something wrong.
Hello Alexis, as far as I know, the lines you pretend to remove are part of the axis, to remove them you must remove all the axis, to do such, ill put a snippet in a new comment due to size restrictions
Thanks Hugo, the plt.axis('off') removes the axis indeed but it also remove the plane at the bottom of the chart which mean my chart looks completely transparent. I'll try to play a bit with this.
Sorry I couldn't be of more help
Thank you for looking into it. I still learned some stuff with your code snippet :)
0

One easy way to remove them is using set_axis_off().
It will remove the axis in a single command.

import numpy as np from matplotlib import cm import matplotlib.pyplot as plt σ = 3 vG = np.linspace(-10, 10, 201) mX, mY = np.meshgrid(vG, vG) mG = np.exp(-np.square(mX) / (2 * σ * σ)) * np.exp(-np.square(mY) / (2 * σ * σ)) hF, hA = plt.subplots(figsize = (6, 6), subplot_kw = {'projection': '3d'}) hA.plot_surface(mX, mY, mG, rstride = 1, cstride = 1, cmap = cm.coolwarm, linewidth = 0, antialiased = False) hA.set(xticks = [], yticks = [], zticks = [], title = 'Gaussian Kernel') hA.set_axis_off() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.