Python 在matplotlib中将三维背景更改为黑色

Python 在matplotlib中将三维背景更改为黑色,python,matplotlib,mplot3d,Python,Matplotlib,Mplot3d,我无法将3d图形的背景更改为黑色。这是我当前的代码。当我将facecolor设置为黑色时,它会将图形内部更改为灰色,这不是我想要的 如果要保持线框轴,可以这样做 ax.w_xaxis.pane.fill = False ax.w_yaxis.pane.fill = False ax.w_zaxis.pane.fill = False 下面是一个完整的示例: fig = plt.figure() ax = plt.axes(projection='3d') x, y, z = np.rando

我无法将3d图形的背景更改为黑色。这是我当前的代码。当我将facecolor设置为黑色时,它会将图形内部更改为灰色,这不是我想要的


如果要保持线框轴,可以这样做

ax.w_xaxis.pane.fill = False
ax.w_yaxis.pane.fill = False
ax.w_zaxis.pane.fill = False
下面是一个完整的示例:

fig = plt.figure()
ax = plt.axes(projection='3d')
x, y, z = np.random.randint(10, size=(3, 250))

ax.scatter(x, y, z, c=np.random.randn(250))

fig.set_facecolor('black')
ax.set_facecolor('black') 
ax.grid(False) 
ax.w_xaxis.pane.fill = False
ax.w_yaxis.pane.fill = False
ax.w_zaxis.pane.fill = False
fig = plt.figure()
ax = plt.axes(projection='3d')
x, y, z = np.random.randint(10, size=(3, 250))

ax.scatter(x, y, z, c=np.random.randn(250))

fig.set_facecolor('black')
ax.set_facecolor('black')
ax.grid(False)
ax.w_xaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
ax.w_yaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
ax.w_zaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))

或者你可以把它们全部藏起来

ax.w_xaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
ax.w_yaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
ax.w_zaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
完整示例:

fig = plt.figure()
ax = plt.axes(projection='3d')
x, y, z = np.random.randint(10, size=(3, 250))

ax.scatter(x, y, z, c=np.random.randn(250))

fig.set_facecolor('black')
ax.set_facecolor('black') 
ax.grid(False) 
ax.w_xaxis.pane.fill = False
ax.w_yaxis.pane.fill = False
ax.w_zaxis.pane.fill = False
fig = plt.figure()
ax = plt.axes(projection='3d')
x, y, z = np.random.randint(10, size=(3, 250))

ax.scatter(x, y, z, c=np.random.randn(250))

fig.set_facecolor('black')
ax.set_facecolor('black')
ax.grid(False)
ax.w_xaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
ax.w_yaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))
ax.w_zaxis.set_pane_color((0.0, 0.0, 0.0, 0.0))

使用Matplotlib的深色背景,它将白色用于通常为黑色的元素(文本、边框等)。它也适用于3D绘图


plt.style.use将为jupyter笔记本中的所有绘图设置样式,我只想为特定绘图设置样式,然后将样式重置为默认值<代码>plt.style.use('default')