Skip to content

3D bar chart with shading is rendered incorrectly #13728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sazas opened this issue Mar 21, 2019 · 6 comments · May be fixed by #26075
Open

3D bar chart with shading is rendered incorrectly #13728

sazas opened this issue Mar 21, 2019 · 6 comments · May be fixed by #26075
Labels
keep Items to be ignored by the “Stale” Github Action topic: mplot3d

Comments

@sazas
Copy link

sazas commented Mar 21, 2019

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

image

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
@ImportanceOfBeingErnest
Copy link
Member

There is clearly room for improvement, this would be the place to start:

# sort by depth (furthest drawn first)
z_segments_2d = sorted(
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
for idx, ((xs, ys, zs), fc, ec)
in enumerate(zip(xyzlist, cface, cedge))),
key=lambda x: x[0], reverse=True)

@seongminp
Copy link

seongminp commented Apr 3, 2019

Setting zsort to 'min' in bar3d (ax1.bar3d(x, y, bottom, width, depth, top, shade=True, zsort='min')) seems to take care of the overlap order problem in the example case and the tutorial case.

However, this only works because the examples are drawing uniformly shaped bars, and the object with the smaller minimum z coordinate is guaranteed to be at the front.

@ImportanceOfBeingErnest Im curious: is there a reasoning behind default zsort being average? Would it be better if it is changed to min? Neither approach is perfect but more use cases might benefit from default zsort being min.

@dstansby
Copy link
Member

I think this is fixed, the outcome of the code above on the master branch is now:
Figure_1

@ImportanceOfBeingErnest
Copy link
Member

That image shows the same problem as the one from the original post. So, no it's not fixed.

Since neither min nor average give in general good visuals, I don't think it makes sense to exchange one for the other.

A possible intermediate solution is to take user-defined plot orders, as in #14508 or #12744 also for the Poly3DCollection.

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 9, 2023
@oscargus
Copy link
Member

oscargus commented Jun 9, 2023

Since there is a recent PR for this, it makes sense to keep it.

@oscargus oscargus added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: mplot3d
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants