0

How can I draw the scatter plot infront of the surface plot? zorder doesen't change the outcome. Scatter3D will always been drawn behind the surface plot.

import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
%matplotlib widget
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

def f(x, y):
    return x**2+y**2

x = np.arange(-5, 5, .1)
y = np.arange(-5, 5, .1)
x, y = np.meshgrid(x, y)
z = f(x, y)

ax.plot_surface(x, y, z, cmap=cm.coolwarm, zorder=1)


ax.scatter3D([0], [0], [0], c='black', zorder=10)
plt.show()

enter image description here

enter image description here

  • 1
    You can set `fig, ax = plt.subplots(subplot_kw={"projection": "3d", "computed_zorder": False})`. By default, matplotlib calculates its own estimated z-order when working in 3D, but that is just a guess depending on the distance of the center of each element to the view position. Setting `computed_zorder=False` allows you to set your own `zorder`. (This is new since matplotlib 3.5) – JohanC Feb 11 '23 at 21:04

0 Answers0