Issue 1:
Bug summary

I am trying to create a 3d histogram following the solution suggested here, which is based on [this matplotlib demo](Create 3D histogram of 2D data). In the finished plot however, the zorder of the bar sides are all messed up.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

# source: https://stackoverflow.com/a/56923189/5472354
def gaus2d(x=0, y=0, mx=0, my=0, sx=1, sy=1):
return 1. / (2. * np.pi * sx * sy) * np.exp(
-((x - mx) ** 2. / (2. * sx ** 2.) + (y - my) ** 2. / (2. * sy ** 2.)))

sample_radius = 5
n_samples = 11
x = np.linspace(-sample_radius, sample_radius, num=n_samples)
y = np.linspace(-sample_radius, sample_radius, num=n_samples)
z = gaus2d(*np.meshgrid(x, y))

fig = plt.figure(constrained_layout=True)
ax = fig.add_subplot(111, projection='3d')
ax.axis('off')
ax.margins(0)

hist, xedges, yedges = np.histogram2d(x, y, bins=n_samples)
xpos, ypos = np.meshgrid(xedges[:-1] + xedges[1:], yedges[:-1] + yedges[1:])

xpos = xpos.flatten() / 2.
ypos = ypos.flatten() / 2.
zpos = np.zeros_like(xpos)

dx = xedges[1] - xedges[0]
dy = yedges[1] - yedges[0]
dz = z.flatten()

cmap = cm.get_cmap('viridis')
max_height = np.max(dz)
min_height = np.min(dz)

rgba = [cmap((k-min_height)/max_height) for k in dz]

ax.bar3d(
xpos, ypos, zpos, dx, dy, dz, color=rgba, zsort='average', shade=True
)

plt.show()

Actual outcome

Expected outcome

A plot where the zorder is correct (although I have to admit, the result looks like a neat art piece).

Additional information

I would guess it has something to do with the zsort argument, but I actually didn't manage to find the documentation for bar3d, only this post. I tried all three possibilities, but none of them worked. Is bar3d depreciated?

Operating system

Windows 10

Matplotlib Version

3.6.1

Matplotlib Backend

backend_interagg

Python version

3.9.7

Jupyter version

No response

Installation

conda

Issue 2:
Bug report

Bug summary

Z-order of rendered planes in 3d bar chart produced by bar3d is wrong. It is seen even in the example here https://matplotlib.org/gallery/mplot3d/3d_bars.html. One of the bars (at location 2, 4, height 6) is drawn on top of the highest bar, even though it supposed to be behind it.

Code for reproduction

A small modification of the code from example to make it more pronounced.

import numpy as np
import matplotlib.pyplot as plt
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import

# setup the figure and axes
fig = plt.figure(figsize=(8, 8))
ax1 = fig.add_subplot(111, projection='3d')

# fake data
_x = np.arange(8)
_y = np.arange(8)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()

top = x + y
bottom = np.zeros_like(top)
width = depth = 1

ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
ax1.set_title('Shaded')
plt.show()

Actual outcome

Everything to the right from diagonal is rendered incorrectly.

Matplotlib version

Tested on two machines with the same results.

Operating system: mac and windows

Matplotlib version:

matplotlib 2.1.2 py36h6d6146d_0

and

matplotlib 3.0.3 py37_0 conda-forge

Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline

Python version:

3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 13:19:00)

[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]

and

3.7.1 | packaged by conda-forge | (default, Mar 13 2019, 13:32:59) [MSC v.1900 64 bit (AMD64)]

Jupyter version (if applicable):

ipython 5.1.0 py36_1

and

ipython 7.3.0 py37h39e3cac_0 conda-forge