Skip to content
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

Issue with shading and layering in 3D-plots #16071

Closed
khashabri opened this issue Jan 2, 2020 · 1 comment
Closed

Issue with shading and layering in 3D-plots #16071

khashabri opened this issue Jan 2, 2020 · 1 comment

Comments

@khashabri
Copy link

Bug report

The following code should show a cylinder that is on a plane. However, as obvious in the 3rd and the 4th image, the shading and layering of matplotlib are not applied correctly and the result looks strange. Using zorder didn't also solve that.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

# Help function to determine the cylinder plot data
def data_for_cylinder_along_z(center_x,center_y,center_z,radius,height_z):
    z = np.linspace(0, height_z, 50)
    theta = np.linspace(0, 2*np.pi, 50)
    theta_grid, z_grid=np.meshgrid(theta, z)
    x_grid = radius*np.cos(theta_grid) + center_x
    y_grid = radius*np.sin(theta_grid) + center_y
    z_grid = z_grid - height_z/2 + center_z
    return x_grid,y_grid,z_grid

# setting up a figure
fig = plt.figure(figsize=(10, 10))
ax = fig.gca(projection='3d')
ax.view_init(90, 0)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_xlim3d(-1, 1)
ax.set_ylim3d(-1, 1)
ax.set_zlim3d(-1, 1)

# plotting a plane
yy, zz = np.meshgrid([-0.5, 0.5], [-0.5, 0.5])
ax.plot_surface(0, yy, zz, color='yellow')

# plotting a cylinder
r = 0.1
Xc,Yc,Zc = data_for_cylinder_along_z(r, 0, 0, r, 1)
ax.plot_surface(Xc, Yc, Zc)

plt.show()

Actual outcome

1
2
3
4

Expected outcome
The plane should be behind the cylinder in all images and the cylinder must be shown.

Matplotlib version

  • Operating system: Ubuntu Linux 64-bit
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.3
@anntzer
Copy link
Contributor

anntzer commented Jan 2, 2020

This is essentially the same issue as #12620: we know about it, but basically can't fix it.

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

2 participants