Skip to content

[Bug]: Bounding box becomes all NaN when a path contains NaN vertices #31982

Description

@jayaprajapatii

Bug summary

When a Path contains one or more NaN vertices along with valid vertices, Path.get_extents() returns an all-NaN Bbox. As a result, a single NaN vertex causes the entire bounding box to become invalid, even though the remaining vertices are valid.

I expected the bounding box to be computed from the valid vertices instead.

Code for reproduction

import numpy as np
from matplotlib.path import Path

verts = np.array([
    [1, 1],
    [np.nan, np.nan],
    [2, 2],
])

path = Path(verts)
print(path.get_extents())

Actual outcome

Bbox(x0=nan, y0=nan, x1=nan, y1=nan)

Expected outcome

I expected the bounding box to be computed from the valid vertices, resulting in a bounding box covering (1, 1) to (2, 2).

i.e Bbox(x0=1.0, y0=1.0, x1=2.0, y1=2.0)

Additional information

Path.iter_segments() defaults to remove_nans=True, treating NaN vertices as missing points during iteration. Since Path.get_extents() computes the bounding box for the same path, I expected it to handle NaN vertices consistently.

Operating system

Ubuntu 24.04

Matplotlib Version

3.12.0.dev229+g1e6bcafd1

Matplotlib Backend

tkagg

Python version

3.12.3

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    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