Skip to content

[Bug]: 3D bar chart appears over axis when using zlim #29482

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
XrioBtw opened this issue Jan 18, 2025 · 8 comments
Open

[Bug]: 3D bar chart appears over axis when using zlim #29482

XrioBtw opened this issue Jan 18, 2025 · 8 comments

Comments

@XrioBtw
Copy link

XrioBtw commented Jan 18, 2025

Bug summary

When I make a 3D bar chart with Matplotlib and change the z axis limits using ax.set_zlim(newMin, newMax) the part of the bar charts below the new z axis minimum value appears above the x and y axis. I would like to ensure that the x and y axis always renders at the top, but I don't know how to achieve this. I tried ax.set_zorder(bigNumber) and ax.xaxis.set_zorder(bigNumber), but it didn't change anything.

Code for reproduction

fig, ax = plt.subplots(subplot_kw = {"projection" : "3d"})
ax.bar3d([1, 1, 2, 2], [1, 2, 1, 2], 0, 1, 1, [2, 3, 1, 4])
ax.set_zlim(2, 4)
ax.set_zorder(10000000) # does not help
plt.show()

Actual outcome

The actual outcome looks like this, where the bar charts render over the x and y axis:

actual-outcome

Expected outcome

Either left or right would be expected outcome:

expected-outcome

Additional information

No response

Operating system

Windows

Matplotlib Version

3.6.0

Matplotlib Backend

TkAgg

Python version

3.10.6

Jupyter version

No response

Installation

pip

@timhoffm
Copy link
Member

Also happens with 3.10.

@WeatherGod
Copy link
Member

WeatherGod commented Jan 19, 2025 via email

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Jan 23, 2025

Thank you @XrioBtw for the great expected outcome images, those really help clarify the question!

This is somewhat a duplicate of #8902

However, I do think there is a good argument for drawing the axes with the same zorder sorting as the rest of the elements, like the bottom right plot. So let's keep this issue open with a focus on that aspect of the question.

@WeatherGod
Copy link
Member

WeatherGod commented Jan 23, 2025 via email

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Jan 28, 2025

Yeah I agree the panes should always be in the back. I do think it's worth experimenting with the axis spines, ticks, and labels either always being on top or getting z order sorted. The bottom right plot seems clearly better than the top one, but I'm sure there's some lurking edge cases.

@sgwu
Copy link

sgwu commented Feb 11, 2025

This is a separate but somewhat related issue. I tried to set the z-axis limit using ax.set_zlim(), but the final limit in the plot always appears to go beyond the set limit. Take @XrioBtw 's plot as an example, the set limit is (2,4), but the actual limit goes below 2 and above 4:

Image

Is there a way to set the z limits exactly as those intended?

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Feb 11, 2025

Hi @sgwu, I would upgrade! That behavior was finally fixed in matplotlib 3.9.0, see: https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.9.0.html#setting-3d-axis-limits-now-set-the-limits-exactly

@sgwu
Copy link

sgwu commented Feb 12, 2025

Thanks @scottshambaugh, this solves my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants