0

Problem:

I am trying to create a wireframe plot and a 3D scatter plot on the same axes in matplotlib, however the scatter plot appears below the wireframe plot even when it should be above it. I tried to change the order of the plotting statements but that did not solve the problem.

Code:

import numpy as np
from matplotlib import pyplot as plt

xgrid, ygrid = np.meshgrid(np.arange(-8, 9, 0.5), np.arange(-8, 9, 0.5))

f = lambda x, y: x**2+y**2
z = f(xgrid, ygrid)

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

ax.scatter3D([0], [0], [150], color="red")
ax.plot_wireframe(xgrid, ygrid, z)

plt.show()

When looking at the graph from above the red dot should be above the wireframe plot, but this code results in the dot being below the graph. It seems that the wireframe is in the foreground at all times.

Red dot below the wireframe plot

Red dot is actually above the wireframe plot

Versions:

Python - 3.8.2

Matplotlib - 3.2.1

Is it possible to fix this problem?

Thank you in advance.

Cookie
  • 1
  • 2
  • works fine for me Python 3.7, Matplotlib 3.2.1, using qt5 backend – DrBwts Apr 24 '20 at 10:12
  • Doesn't work for me even with Python 3.7, could this be because I'm using MacOS? – Cookie Apr 24 '20 at 10:32
  • I don't think macOS is the problem, I tried it on my windows machine with different backends and found the same problem – Aly Hosny Apr 24 '20 at 11:20
  • which backend are you using? just checked it with qt4 & works fine – DrBwts Apr 24 '20 at 15:35
  • @DrBwts matplotlib.get_backend() returns 'MacOSX' – Cookie Apr 24 '20 at 15:46
  • It appears that when looking almost directly downwards onto the graph it's displayed correctly but as soon as you change the elevation by 10º-15º the dot just moves behind the graph. – Cookie Apr 24 '20 at 16:01
  • Do you perhaps need `ax = fig.add_subplot(111, projection='3d', computed_zorder=False)`, like in this answer: https://stackoverflow.com/a/71134800/1386750 ? – AstroFloyd Apr 18 '22 at 14:06

0 Answers0