On the basis of the scatterplot example of matplotlib, how can I change the gray background color of the 3 axes grid planes? I would like to set it to white, keeping the grid lines with the default gray color. I found this question but I couldn't apply it to the example. Thanks.
Asked
Active
Viewed 3.8k times
2 Answers
42
Using the same example. You can set the pane color using the set_pane_color
method as described here http://matplotlib.org/mpl_toolkits/mplot3d/api.html#axis3d. You can set the color using the RGBA tuple:
# scatter3d_demo.py
# ...
# Set the background color of the pane YZ
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
plt.show()

Pablo Navarro
- 8,244
- 2
- 43
- 52
-
3Perfect, thanks. Doing the same for yaxis and zaxis is pretty straightforward – user1520280 Oct 05 '12 at 13:10
38
For a slightly different approach, see below:
# Get rid of colored axes planes
# First remove fill
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
# Now set color to white (or whatever is "invisible")
ax.xaxis.pane.set_edgecolor('w')
ax.yaxis.pane.set_edgecolor('w')
ax.zaxis.pane.set_edgecolor('w')
# Bonus: To get rid of the grid as well:
ax.grid(False)
See this blog post that I used as my source.

S.A.
- 1,819
- 1
- 24
- 39
-
1The command `set_edgecolor` did not work for me on Linux. Hopefully, I found `ax.set_axis_off()` to be effective at removing the axes and the background at all :) – C-3PO Apr 07 '22 at 08:05
-
Using PyPlot.jl in julia, the command set_edgecolor does not work either. But the ax.set_axis_off() works perfectly. – Rudolf Smorka Aug 11 '23 at 10:50