'Hide tick text but keep grid for 3D-plot

I have searched far and wide for a way to remove the tick text but not the actual grid lines from a 3D matplotlib plot. I unfortunately still have no idea how to do it, as most solutions seem to only work for 2D figures.

I tried the follwing code:

ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

but this also removed the gridlines. I have provided an example of the figure I want the tick text removed from, and an example of what happens when use the code stump above.

enter image description here enter image description here

Any help is greatly appreciated!



Solution 1:[1]

One way is to set numeric ticks and empty label ticks:

import matplotlib.pyplot as plt
import numpy as np

xmin, xmax = -10, 10
ymin, ymax = -10, 10
zmin, zmax = -10, 10
x = np.random.uniform(xmin, xmax, 20)
y = np.random.uniform(ymin, ymax, 20)
z = np.random.uniform(zmin, zmax, 20)

xticks = np.arange(xmin, xmax+1, 3)
yticks = np.arange(xmin, xmax+1, 3)
zticks = np.arange(xmin, xmax+1, 3)
empty_labels_x = ["" for i in range(len(xticks))]
empty_labels_y = ["" for i in range(len(yticks))]
empty_labels_z = ["" for i in range(len(zticks))]

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.scatter(x, y, z)
ax.set_xticks(xticks, empty_labels_x)
ax.set_yticks(yticks, empty_labels_y)
ax.set_zticks(zticks, empty_labels_z)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Davide_sd