Skip to content

mplot3d failed to clip bar charts if zlim is set. #8902

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
a113n opened this issue Jul 17, 2017 · 6 comments
Open

mplot3d failed to clip bar charts if zlim is set. #8902

a113n opened this issue Jul 17, 2017 · 6 comments
Labels
Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues keep Items to be ignored by the “Stale” Github Action New feature topic: mplot3d

Comments

@a113n
Copy link

a113n commented Jul 17, 2017

Bug report

Bug summary

mplot3d failed to clip bar charts if zlim is set.

Code for reproduction

# Adapter from http://matplotlib.org/2.0.2/examples/mplot3d/bars3d_demo.html
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
    xs = np.arange(20)
    ys = np.random.rand(20)

    # You can provide either a single color or an array. To demonstrate this,
    # the first bar of each set will be colored cyan.
    cs = [c] * len(xs)
    cs[0] = 'c'
    ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Set zlim3d
ax.set_zlim3d(bottom=0.2, top=1)

plt.show()

Actual outcome

test

Expected outcome
The z-axis would be clipped according to the zlim_3d parameters properly

Matplotlib version

  • Operating System: Windows 10 1703
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6
  • Jupyter Version (if applicable):
  • Other Libraries:

Matplotlib installed from pip.

@tacaswell tacaswell added this to the unassigned milestone Jul 17, 2017
@tacaswell tacaswell added topic: mplot3d New feature Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Jul 17, 2017
@tacaswell
Copy link
Member

To my understanding we do not compute any sort of 3D intersections or have a proper z-buffer (either of which could be used to implement this) and both of which would be pretty major efforts to implement.

@a113n are you interested in working on this?

@a113n
Copy link
Author

a113n commented Jul 18, 2017

@tacaswell instead of implementing code to compute 3D intersections or z-buffer, could zlim_3d clip the data properly just like the workaround below?

# Adapted from http://matplotlib.org/2.0.2/examples/mplot3d/bars3d_demo.html
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
import numpy as np


# Funcformatter to simulate zlim_3d
def major_formatter(x, pos):
    return "{:.1f}".format(x+0.2)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
    xs = np.arange(20)
    ys = np.random.rand(20)
    
    # Simulate zlim_3d by subtracting the min limit
    ys -= 0.2
    ys[ys < 0] = 0

    # You can provide either a single color or an array. To demonstrate this,
    # the first bar of each set will be colored cyan.
    cs = [c] * len(xs)
    cs[0] = 'c'
    ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Shift the tick labels up by 0.2
ax.zaxis.set_major_formatter(ticker.FuncFormatter(major_formatter))

plt.show()

Result:
test

@tacaswell
Copy link
Member

That works for this case where you know the shift and use it to both adjust the data and the tick labels. However I don't see how to generalize it.

It would also be odd if it only worked in the z-direction, not x and y.

@QuLogic
Copy link
Member

QuLogic commented Jun 23, 2018

The code passes zdir='y' which is why the layering is in the y direction instead of z.

@story645 story645 modified the milestones: unassigned, needs sorting Oct 6, 2022
@github-actions
Copy link

github-actions bot commented Oct 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 Oct 9, 2023
@QuLogic QuLogic added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Oct 11, 2023
@scottshambaugh
Copy link
Contributor

scottshambaugh commented Nov 28, 2023

There is some discussion about this desired behavior in #25804

#27349 will implement option B from the graphic below, but option C is really the thrust of the original question here.
image

Unfortunately, implementing that would require a huge rewrite of the 3D renderer to do proper culling with a z-buffer or 3D intersections, as @tacaswell mentioned in his comment. I don't think there's anyone able to do that right now, though if someone wants to take it on as a project it'd be awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Hard https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues keep Items to be ignored by the “Stale” Github Action New feature topic: mplot3d
Projects
None yet
Development

No branches or pull requests

5 participants