10000 Additional fixes for improved nonfinite scatter support. · matplotlib/matplotlib@6105980 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6105980

Browse files
committed
Additional fixes for improved nonfinite scatter support.
1 parent 8c0a24e commit 6105980

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
PathCollections created with `~.Axes.scatter` now keep track of invalid points
2+
``````````````````````````````````````````````````````````````````````````````
3+
4+
Previously, points with nonfinite (infinite or nan) coordinates would not be
5+
included in the offsets (as returned by `PathCollection.get_offsets`) of a
6+
`PathCollection` created by `~.Axes.scatter`, and points with nonfinite values
7+
(as specified by the *c* kwarg) would not be included in the array (as returned
8+
by `PathCollection.get_array`)
9+
10+
Such points are now included, but masked out by r 8000 eturning a masked array.
11+
12+
If the *plotinvalid* kwarg to `~.Axes.scatter` is set, then points with
13+
nonfinite values are plotted using the bad color of the `PathCollection`\ 's
14+
colormap (as set by `Colormap.set_bad`).

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,7 +4180,7 @@ def _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape,
41804180
label_namer="y")
41814181
def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
41824182
vmin=None, vmax=None, alpha=None, linewidths=None,
4183-
verts=None, edgecolors=None, plotinvalid=False,
4183+
verts=None, edgecolors=None, *, plotinvalid=False,
41844184
**kwargs):
41854185
"""
41864186
A scatter plot of *y* vs *x* with varying marker size and/or color.
@@ -4314,25 +4314,14 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43144314
c, edgecolors, kwargs, xshape, yshape,
43154315
get_next_color_func=self._get_patches_for_fill.get_next_color)
43164316

4317-
# if plotinvalid and colors == None:
4318-
# # Do full color mapping; don't remove invalid c entries.
4319-
# ind = np.arange(len(c))
4320-
# x, y, s, ind, colors, edgecolors, linewidths =\
4321-
# cbook.delete_masked_points(
4322-
# x, y, s, ind, colors, edgecolors, linewidths)
4323-
# c = np.ma.masked_invalid(c[ind])
4324-
# else:
4325-
# x, y, s, c, colors, edgecolors, linewidths =\
4326-
# cbook.delete_masked_points(
4327-
# x, y, s, c, colors, edgecolors, linewidths)
4328-
4329-
if plotinvalid and colors == None:
4317+
if plotinvalid and colors is None:
43304318
c = np.ma.masked_invalid(c)
4331-
x, y, s, colors, edgecolors, linewidths =\
4332-
cbook.combine_masks(x, y, s, colors, edgecolors, linewidths)
4319+
x, y, s, colors, edgecolors, linewidths = \
4320+
cbook._combine_masks(x, y, s, colors, edgecolors, linewidths)
43334321
else:
4334-
x, y, s, c, colors, edgecolors, linewidths =\
4335-
cbook.combine_masks(x, y, s, c, colors, edgecolors, linewidths)
4322+
x, y, s, c, colors, edgecolors, linewidths = \
4323+
cbook._combine_masks(
4324+
x, y, s, c, colors, edgecolors, linewidths)
43364325

43374326
scales = s # Renamed for readability below.
43384327

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ def delete_masked_points(*args):
10811081
return margs
10821082

10831083

1084-
def combine_masks(*args):
1084+
def _combine_masks(*args):
10851085
"""
10861086
Find all masked and/or non-finite points in a set of arguments,
10871087
and return the arguments as masked arrays with a common mask.

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,7 @@ def quiverkey(Q, X, Y, U, label, **kw):
28352835
def scatter(
28362836
x, y, s=None, c=None, marker=None, cmap=None, norm=None,
28372837
vmin=None, vmax=None, alpha=None, linewidths=None, verts=None,
2838-
edgecolors=None, plotinvalid=False, *, data=None, **kwargs):
2838+
edgecolors=None, *, plotinvalid=False, data=None, **kwargs):
28392839
__ret = gca().scatter(
28402840
x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
28412841
vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,

lib/matplotlib/tests/test_colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_colorbar_single_scatter():
197197
# the norm scaling within the colorbar must ensure a
198198
# finite range, otherwise a zero denominator will occur in _locate.
199199
plt.figure()
200-
x = y = [0]
200+
x = y = [0]
201201
z = [50]
202202
cmap = plt.get_cmap('jet', 16)
203203
cs = plt.scatter(x, y, z, c=z, cmap=cmap)

0 commit comments

Comments
 (0)
0