Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyplot - '3D' scatter plot - zlabel?

Minimum working example:

#Python
import matplotlib.pyplot as plt

x = [0, 1, 2, 3, 4, 5]
y = [0, 1, 2, 3, 4, 5]
z = [0, 1, 2, 3, 4, 5]

fig = plt.figure()
ax = plt.axes(projection="3d")
ax.scatter(x, y, z, c='g', s=20)
plt.xlabel("X data")
plt.ylabel("Y data")
#plt.zlabel("Z data") DOES NOT WORK
ax.view_init(60,35)
plt.show()

Question: how to set up the label of the Z axis? For some reason plt has the xlabel and ylabel properties, but not the zlabel.

like image 309
Bart M Avatar asked Oct 20 '25 11:10

Bart M


1 Answers

For 3D plots the labels need to be changed using the axes objects.

Try something like this

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
like image 98
Iddo Sadeh Avatar answered Oct 23 '25 00:10

Iddo Sadeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!