Mark Bakker
Mark Bakker

Reputation: 821

how to change color of axis in 3d matplotlib figure?

The color of the axis (x, y, z) in a 3d plot using matplotlib is black by default. How do you change the color of the axis? Or better yet, how do you make them invisible?

%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.xaxis.set_visible(False)  # doesn't do anything

And there doesn't seem to be a ax.xaxis.set_color function. Any thoughts on how to make the axis invisible or change the color?

Upvotes: 1

Views: 1259

Answers (1)

Sheldore
Sheldore

Reputation: 39042

You can combine your method with the approach provided here. I am showing an example that affects all three axes. In Jupyter Notebook, using tab completion after ax.w_xaxis.line., you can discover other possible options

ax.w_xaxis.line.set_visible(False)
ax.w_yaxis.line.set_color("red")
ax.w_zaxis.line.set_color("blue")

To change the tick colors, you can use

ax.xaxis._axinfo['tick']['color']='r'
ax.yaxis._axinfo['tick']['color']='g'
ax.zaxis._axinfo['tick']['color']='b' 

To hide the ticks

for line in ax.xaxis.get_ticklines():
    line.set_visible(False)

enter image description here

Upvotes: 1

Related Questions