Skip to content

[Bug]: Poor rendering of Poly3DCollection with axlim clipping #29373

@scottshambaugh

Description

@scottshambaugh

Bug summary

When plotting Poly3DCollection with axlim_clip=True, the patch is split into multiple patches and renders poorly.

I am leaning towards this being the "correct" behavior, but want to open the bug report to document it and see if anyone has a solution that solves this cleanly.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

# Generate some random data
np.random.seed(42)
x = np.arange(10)
y = np.zeros_like(x)
z = np.random.randint(5, 10, 10)

fig, ax = plt.subplots(1, 1, subplot_kw={'projection': '3d'})
ax.fill_between(x, y, z, x, 0, 0, axlim_clip=True)
ax.set_xlim(0, 8)
plt.show()

Actual outcome

image

Expected outcome

image

Additional information

There are two workarounds for this particular example:

  1. Restrict the data to the x=[0, 8] range before plotting.
  2. Use fill_between with the quad mode like so:
ax.fill_between(x, y, z, x, 0, 0, axlim_clip=True, mode='quad', shade=False)

Matplotlib Version

3.10.0

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions