Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
0d8bfed
a0662df
d065990
eb97647
aa6e01e
ae488b3
c8d7ff3
0072668
679603a
39cfd56
4bdcd3c
28f0692
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff 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() |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -4327,6 +4327,8 @@ | ||||||||||||
Argument precedence for facecolors: | ||||||||||||
- kwargs['facecolor'] if 'none' | ||||||||||||
- kwargs['facecolors'] if 'none' | ||||||||||||
- c (if not None) | ||||||||||||
- kwargs['facecolor'] | ||||||||||||
- kwargs['facecolors'] | ||||||||||||
@@ -4338,6 +4340,7 @@ | ||||||||||||
- kwargs['edgecolor'] | ||||||||||||
- edgecolors (is an explicit kw argument in scatter()) | ||||||||||||
- kwargs['color'] (==kwcolor) | ||||||||||||
- c (if not None) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think this is only true if | ||||||||||||
- 'face' if not in classic mode else None | ||||||||||||
Parameters | ||||||||||||
@@ -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, or *None* if a colormap is used. | ||||||||||||
""" | ||||||||||||
facecolors = kwargs.pop('facecolors', None) | ||||||||||||
@@ -4398,7 +4401,12 @@ | ||||||||||||
if facecolors is None: | ||||||||||||
facecolors = kwcolor | ||||||||||||
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 | ||||||||||||
@@ -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 | ||||||||||||
@@ -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", | ||||||||||||
@@ -4627,10 +4639,22 @@ | ||||||||||||
c, edgecolors, kwargs, x.size, | ||||||||||||
get_next_color_func=self._get_patches_for_fill.get_next_color) | ||||||||||||
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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||||||||
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 = \ | ||||||||||||
cbook._combine_masks(x, y, s, colors, linewidths) | ||||||||||||
Comment on lines +4655 to +4657 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||||||||||||
@@ -4704,7 +4728,9 @@ | ||||||||||||
alpha=alpha, | ||||||||||||
) | ||||||||||||
collection.set_transform(mtransforms.IdentityTransform()) | ||||||||||||
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))): | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||||||||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(): | ||
@@ -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) | ||
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(): | ||