Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

scatter() should not drop data points at nonfinite coordinates #12801

Closed
Milestone
@anntzer

Description

@anntzer

Currently, scatter() completely drops data points at nonfinite coordinates from the PathCollection it builds:

fig, ax = plt.subplots()x = [0, 1, np.nan, 3]y = [0, 1, 2, 3]c = [0, 1, 2, 3]pc = ax.scatter(x, y, c=c)print(pc.get_offsets())

results in

[[0. 0.] [1. 1.] [3. 3.]]

i.e. the [2, nan] point is not recorded anywhere, even thoughwe could just as well keep track of it and let therenderer do the job of not rendering nonfinite points.

As a result, this makes event picking less-than-optimal: adding

fig.canvas.mpl_connect("button_press_event", lambda event: print(pc.contains(event)))

to the code above, one sees that the first point is picked at index 0 ((True, {'ind': array([0], dtype=int32)}) is printed when clicking on it), the second one at index 1, and the last one at index 2. So one cannot use the resulting index to lookup intox/y/c, one has to index intopc.get_offsets()/pc.get_array(); and if one wants to index into someother array (my actual use case), one needs to manually count the nans inx/y/c and do the index conversion.
As a comparison point,Line2D does keep invalid points around and lets the renderer kill them.

Likewise, points with nonfinite values are dropped:

pc = ax.scatter([0, 1, 2, 3], [0, 1, 2, 3], c=[0, np.nan, np.inf, 1])

results in behavior similar to the one described above.
In this specific case, I actually think nonfinite points should respect the colormap's colors set byset_under/set_over/set_bad (right now they don't, they are again wiped out of existence) -- after all that's exactly what these "extra" colors are for.

This second issue (invalidc) has already been reported elsewhere and there are already PRs for it:#4354/#9891/#12422.

mpl master/3.0.2
Arch Linux/Py3.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp