Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: plot3d depth test is off #24767

Open
@ubitux

Description

@ubitux

Bug summary

The depth testing of points depends only on their coordinates and doesn't take into account the camera angle.

mpl-3d-depth.mp4

Code for reproduction

import matplotlib.pyplot as plt

colors = [
    0x010101, 0x050405, 0x080809, 0x0d0b0c, 0x0d101e, 0x110e0f, 0x11192f, 0x151213,
    0x161419, 0x171514, 0x18181a, 0x182133, 0x1d191b, 0x1e2741, 0x1f1c1d, 0x214e92,
    0x221e11, 0x222121, 0x23539c, 0x264b76, 0x285ba6, 0x2860ae, 0x2866b3, 0x29272c,
    0x293551, 0x2a2322, 0x2a6bbb, 0x2b71c0, 0x2b75c3, 0x2c2d2f, 0x2c3544, 0x2d2b23,
    0x2d63b0, 0x2e68b4, 0x2f79c8, 0x306ab8, 0x306cbd, 0x3070bf, 0x307ecc, 0x3175c2,
    0x3183d0, 0x323031, 0x362e2e, 0x363536, 0x366fbb, 0x3683d0, 0x3773c0, 0x3777c3,
    0x3779c8, 0x3880ca, 0x3889d4, 0x3b2920, 0x3b3630, 0x3b3a3c, 0x3b3c43, 0x3b90d8,
    0x3c2018, 0x3c2f1f, 0x3c3938, 0x3e7dc3, 0x3e7fc8, 0x3e8cd4, 0x3f84cc, 0x3f86d1,
    0x403536, 0x412e2d, 0x4190d7, 0x4194d9, 0x42371f, 0x423828, 0x438fd2, 0x4398db,
    0x444242, 0x463e41, 0x464648, 0x473c3c, 0x485064, 0x488ad2, 0x4898dc, 0x4989cb,
    0x4a3930, 0x4a4b50, 0x4a93d7, 0x4b3c37, 0x4b8ac6, 0x4b9ede, 0x4c4f59, 0x4e452c,
    0x4e91cf, 0x4f453c, 0x504537, 0x505055, 0x534842, 0x534c49, 0x535b69, 0x5398d8,
    0x53a2e0, 0x545050, 0x559ddd, 0x566674, 0x5681ab, 0x57a7e1, 0x585959, 0x58a0d8,
    0x58a3dd, 0x5995ca, 0x5999d1, 0x5aa6dd, 0x5bace1, 0x5daee4, 0x633f32, 0x63524f,
    0x644543, 0x645954, 0x64605e, 0x646263, 0x64656b, 0x64b1e5, 0x655241, 0x657487,
    0x659cc9, 0x65a4d2, 0x65aadb, 0x65ace2, 0x6790b3, 0x686a6e, 0x695f53, 0x6a6e73,
    0x6a96bd, 0x6ab5e6, 0x6b7479, 0x6b7e8a, 0x6db1e3, 0x6db5e2, 0x6e86a1, 0x6ea4cb,
    0x70acd8, 0x73aad2, 0x747477, 0x747f89, 0x74b0da, 0x75b8e6, 0x76574a, 0x774f3a,
    0x775b55, 0x776a66, 0x787b7c, 0x78b8e1, 0x7a6955, 0x7a736c, 0x7e8790, 0x7ea6c6,
    0x7f97ad, 0x7fb5da, 0x808285, 0x80bbe2, 0x817e7c, 0x81afd0, 0x84bfe2, 0x87888a,
    0x88725f, 0x88b7d8, 0x897353, 0x8a7a6c, 0x8abedc, 0x8b959e, 0x8d8379, 0x8e5134,
    0x8e8b8b, 0x8e9396, 0x90adc6, 0x90b3ce, 0x91a0aa, 0x91bdd9, 0x92604f, 0x92795f,
    0x929291, 0x92b9d1, 0x94806c, 0x95bdd7, 0x96938b, 0x989a9d, 0x999897, 0x9a8779,
    0x9b9283, 0x9cbfd8, 0x9d9174, 0x9da4aa, 0x9e9f9f, 0xa1846b, 0xa4a5a7, 0xa57c60,
    0xa5abae, 0xa6b9c6, 0xa6bdc9, 0xa7a29d, 0xa99e8f, 0xa9b6c0, 0xaa946f, 0xaaaaaa,
    0xac946b, 0xac9773, 0xacafb1, 0xacb2ba, 0xad9a77, 0xad9c84, 0xaf5f25, 0xafaa9e,
    0xb09e7d, 0xb0b1b1, 0xb3b8bb, 0xb4bec3, 0xb5b4b2, 0xb77750, 0xb7a68d, 0xb8b8b4,
    0xb9a985, 0xbaa246, 0xbbbbbc, 0xbbc4c9, 0xbcaf8f, 0xbcb4ab, 0xbcc1c1, 0xbd732d,
    0xbeceda, 0xc1b29c, 0xc1c3c3, 0xc2b9ac, 0xc4beb0, 0xc5c5c4, 0xc6cac8, 0xc6ccce,
    0xc7b590, 0xc8bc9d, 0xcbc5bf, 0xcec3ad, 0xceccc6, 0xcfd0cf, 0xd1c09d, 0xd3cec4,
    0xd3d2d1, 0xd5d5d6, 0xd6c7ac, 0xd6d0c7, 0xd8d7cf, 0xd9dbda, 0xdbcfb1, 0xdcd1c2,
    0xe1d8c8, 0xe2e0db, 0xe5e5e4, 0xe8dfcb, 0xeeece9, 0xf4f5f6, 0xfdfcfb,
]

ax = plt.figure().add_subplot(projection="3d")
for c in colors:
    r, g, b = c >> 16 & 0xff, c >> 8 & 0xff, c & 0xff
    ax.plot(r/0xff, g/0xff, b/0xff, "o", color=f"#{c:06x}")
plt.show()

Actual outcome

Whether we look from an angle or the opposite one, we always have the higher coordinates visible in front (the clear ones, that is the closest to (1,1,1)).

Expected outcome

The darker points ((0,0,0)) should be in front when looking from the "bottom" angle, and the lighter points from the other angle (like currently).

Additional information

No response

Operating system

Arch

Matplotlib Version

3.6.2

Matplotlib Backend

GTK3Agg

Python version

3.10.8

Jupyter version

No response

Installation

Linux package manager

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions