1

The z-label does not show up in my figure. What is wrong?

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
plt.show()

Output

Neither ax.set_zlabel("z") nor ax.set(zlabel="z") works. The x- and y-labels work fine.

Moritz
  • 27
  • 7

1 Answers1

2

That's a padding issue.

labelpadfloat The distance between the axis label and the tick labels. Defaults to rcParams["axes.labelpad"] (default: 4.0) = 4.

You can use matplotlib.axis.ZAxis.labelpad to adjust this value for the z-axis :

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("StackOverflow", rotation=90)
ax.zaxis.labelpad=-0.7 # <- change the value here
plt.show();

Output :

enter image description here

Timeless
  • 22,580
  • 4
  • 12
  • 30
  • I find this a bit unsettling. There is so much space on the left-hand side of the figure. It is not clear to me, why can we simply put the whole figure a bit to the left. – zltn.guba May 13 '23 at 13:27