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

Fix inability to use empty markers in scatter#25593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
maramiulescu wants to merge12 commits intomatplotlib:main
base:main
Choose a base branch
Loading
frommaramiulescu:fix-issue-24404
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
0d8bfed
Fix trailing whitespace
maramiulescuMar 31, 2023
a0662df
Update scatter test to work with new behavior
maramiulescuMar 31, 2023
d065990
Add tests
maramiulescuMar 31, 2023
eb97647
Changed typechecks to isinstance, line-continuations to brackets
ewpardijsMar 31, 2023
aa6e01e
Merge branch 'matplotlib:main' into fix-issue-24404
maramiulescuApr 1, 2023
ae488b3
Merge branch 'matplotlib:main' into fix-issue-24404
maramiulescuApr 20, 2023
c8d7ff3
Use isinstance for type checking
maramiulescuApr 20, 2023
0072668
Add typecheck for maskedarrays
ewpardijsApr 20, 2023
679603a
Add what's new
maramiulescuApr 20, 2023
39cfd56
PR comments and updated whats new
ewpardijsApr 21, 2023
4bdcd3c
Merge branch 'matplotlib:main' into fix-issue-24404
ewpardijsMay 5, 2023
28f0692
Merge branch 'matplotlib:main' into fix-issue-24404
maramiulescuMay 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletionsdoc/users/next_whats_new/updated_scatter.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
Enable configuration of empty markers in `~matplotlib.axes.Axes.scatter`
------------------------------------------------------------------------

`~matplotlib.axes.Axes.scatter` can now be configured to plot empty markers by setting ``facecolors`` to *'none'* and defining ``c``. In this case, ``c`` will be now used as ``edgecolor``.

.. plot::
:include-source: true
:alt: A simple scatter plot which illustrates the use of the *scatter* function to plot empty markers.

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 10)
plt.scatter(x, x, c=x, facecolors='none', marker='o')
plt.show()
34 changes: 30 additions & 4 deletionslib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4327,6 +4327,8 @@

Argument precedence for facecolors:

- kwargs['facecolor'] if 'none'
- kwargs['facecolors'] if 'none'
- c (if not None)
- kwargs['facecolor']
- kwargs['facecolors']
Expand All@@ -4338,6 +4340,7 @@
- kwargs['edgecolor']
- edgecolors (is an explicit kw argument in scatter())
- kwargs['color'] (==kwcolor)
- c (if not None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is only true iffacecolors is"none". Otherwise I would expect the test case(dict(c='b'), None), from the edited test to instead be(dict(c='b'), np.array([[0, 0, 1, 1]])), similar to the last test case added... I think, at least?

tacaswell reacted with thumbs up emoji
- 'face' if not in classic mode else None

Parameters
Expand DownExpand Up@@ -4371,7 +4374,7 @@
colors : array(N, 4) or None
The facecolors as RGBA values, or *None* if a colormap is used.
edgecolors
The edgecolor.
The edgecolor, or *None* if a colormap is used.

"""
facecolors = kwargs.pop('facecolors', None)
Expand All@@ -4398,7 +4401,12 @@
if facecolors is None:
facecolors = kwcolor

if edgecolors is None and not mpl.rcParams['_internal.classic_mode']:
edge_from_c = edgecolors is None and c is not None

facecolors_none = cbook._str_lower_equal(facecolors, 'none')
if (edgecolors is None and not mpl.rcParams['_internal.classic_mode']
and (not edge_from_c or not facecolors_none)):

edgecolors = mpl.rcParams['scatter.edgecolors']

c_was_none = c is None
Expand DownExpand Up@@ -4449,6 +4457,8 @@
if not c_is_mapped:
try: # Is 'c' acceptable as PathCollection facecolors?
colors = mcolors.to_rgba_array(c)
if edge_from_c and facecolors is not None:
edgecolors = mcolors.to_rgba_array(c)
except (TypeError, ValueError) as err:
if "RGBA values should be within 0-1 range" in str(err):
raise
Expand All@@ -4467,6 +4477,8 @@
raise invalid_shape_exception(len(colors), xsize)
else:
colors = None # use cmap, norm after collection is created
if cbook._str_lower_equal(facecolors, 'none'):
colors = facecolors
return c, colors, edgecolors

@_preprocess_data(replace_names=["x", "y", "s", "linewidths",
Expand DownExpand Up@@ -4627,10 +4639,22 @@
c, edgecolors, kwargs, x.size,
get_next_color_func=self._get_patches_for_fill.get_next_color)

if plotnonfinite and colors is None:
if cmap and norm and not orig_edgecolor:
# override edgecolor based on cmap and norm presence
edgecolors = 'face'

if plotnonfinite and (colors is None and edgecolors is None):
c = np.ma.masked_invalid(c)
x, y, s, linewidths = \
cbook._combine_masks(x, y, s, linewidths)
Comment on lines +4648 to +4649
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
x,y,s,linewidths= \
cbook._combine_masks(x,y,s,linewidths)
x,y,s,linewidths=cbook._combine_masks(x,y,s,linewidths)

elif plotnonfinite and colors is None:
c = np.ma.masked_invalid(c)
x, y, s, edgecolors, linewidths = \
cbook._combine_masks(x, y, s, edgecolors, linewidths)
elif plotnonfinite and edgecolors is None:
c = np.ma.masked_invalid(c)
x, y, s, colors, linewidths = \

Check warning on line 4656 in lib/matplotlib/axes/_axes.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/axes/_axes.py#L4655-L4656

Added lines #L4655 - L4656 were not covered by tests
cbook._combine_masks(x, y, s, colors, linewidths)
Comment on lines +4655 to +4657
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
c=np.ma.masked_invalid(c)
x,y,s,colors,linewidths= \
cbook._combine_masks(x,y,s,colors,linewidths)
c=np.ma.masked_invalid(c)
x,y,s,colors,linewidths=cbook._combine_masks(x,y,s,colors,linewidths)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This also needs a test case that will cover this line.

else:
x, y, s, c, colors, edgecolors, linewidths = \
cbook._combine_masks(
Expand DownExpand Up@@ -4704,7 +4728,9 @@
alpha=alpha,
)
collection.set_transform(mtransforms.IdentityTransform())
if colors is None:

if ((colors is None or edgecolors is None) and not mcolors.is_color_like(c) and
(not isinstance(c, np.ndarray) or isinstance(c, np.ma.MaskedArray))):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why are we gating on the type here? Will our normalization above ensure other iterables will be converted to numpy arrays?

collection.set_array(c)
collection.set_cmap(cmap)
collection.set_norm(norm)
Expand Down
7 changes: 6 additions & 1 deletionlib/matplotlib/tests/test_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2749,6 +2749,8 @@ def get_next_color():
(dict(c='b', edgecolor='r', edgecolors='g'), 'r'),
(dict(color='r'), 'r'),
(dict(color='r', edgecolor='g'), 'g'),
(dict(facecolors='none'), None),
(dict(c='b', facecolors='none'), np.array([[0, 0, 1, 1]]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we need to cover the case of colormapping + empty here as well.

])
def test_parse_scatter_color_args_edgecolors(kwargs, expected_edgecolors):
def get_next_color():
Expand All@@ -2759,7 +2761,10 @@ def get_next_color():
_, _, result_edgecolors = \
mpl.axes.Axes._parse_scatter_color_args(
c, edgecolors, kwargs, xsize=2, get_next_color_func=get_next_color)
assert result_edgecolors == expected_edgecolors
if isinstance(expected_edgecolors, np.ndarray):
assert_allclose(result_edgecolors, expected_edgecolors)
else:
assert result_edgecolors == expected_edgecolors


def test_parse_scatter_color_args_error():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp