Reputation: 121
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()
Neither ax.set_zlabel("z")
nor ax.set(zlabel="z")
works. The x- and y-labels work fine.
Upvotes: 10
Views: 5840
Reputation: 1
Sharing a workaround that resolved the issue for me. To make the z-label visible, I added a title to the figure and padded it with empty spaces to artificially adjust the figure's layout and increase the effective width. Here's the code:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
# Add a padded title to adjust the layout
ax.set_title(" " * 35 + "Your Title" + " " * 35)
plt.show()
Upvotes: 0
Reputation: 37737
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 :
Upvotes: 10