1

I am drawing a 3d graph with matplotlib and trying to change the order of some scatters with the attribute "zorder". The object with the highest zorder should be placed on top, but it failed. Here is my code:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(projection= '3d')

coorx = [1,2,3,4]
coory = [1,1,1,1]
coorz = [1,1,1,1]

for i in range(4):
    ax.scatter(coorx[i], coory[i], coorz[i], s = coorx[i]*40, alpha = 1, c = 'orange', zorder = 1)
    ax.scatter(coorx[i], coory[i], coorz[i], s = 2, alpha = 1, c = 'white', zorder = 0)

plt.show()

and here is the result: figure

As shown in the code, I have specified the orange points with higher zorder, but they are actually below the white ones.

I have searched the Internet and read the document, but they are of little help.

Tina
  • 21
  • 2

1 Answers1

1

Interesting. I'm not sure why but zorder seems to behave properly when called with ax.plot rather than ax.scatter, as follows:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(projection= '3d')

coorx = [1,2,3,4]
coory = [1,1,1,1]
coorz = [1,1,1,1]


ax.plot(coorx, coory, coorz, markersize = 10, marker = 'o', alpha = 1, c = 'orange', zorder = 1, linestyle = '')
ax.plot(coorx, coory, coorz, markersize = 1, marker = 'o', alpha = 1, c = 'white', zorder = 0, linestyle = '')

plt.show()

which produces: enter image description here

Changing to

ax.plot(coorx, coory, coorz, markersize = 10, marker = 'o', alpha = 1, c = 'orange', zorder = 0, linestyle = '')
ax.plot(coorx, coory, coorz, markersize = 1, marker = 'o', alpha = 1, c = 'white', zorder = 1, linestyle = '')

yields

enter image description here

My guess would be scatter doesn't know how to deal with zorder but plot does - but that is a total guess.

Vin
  • 929
  • 1
  • 7
  • 14