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: uses scatter markers with facecolor = 'none'#30671

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
cairibep wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromcairibep:fix/empty_markers_scatter
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
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
16 changes: 15 additions & 1 deletionlib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5231,6 +5231,9 @@
orig_edgecolor = edgecolors
if edgecolors is None:
orig_edgecolor = kwargs.get('edgecolor', None)
# Store original facecolors value before parsing
orig_facecolors = kwargs.get('facecolors', kwargs.get('facecolor', None))

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

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Blank line contains whitespaceRaw Output:message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/axes/_axes.py" range:{start:{line:5236 column:1} end:{line:5236 column:9}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:5236 column:1} end:{line:5236 column:9}}}
c, colors, edgecolors = \
self._parse_scatter_color_args(
c, edgecolors, kwargs, x.size,
Expand DownExpand Up@@ -5308,9 +5311,20 @@

offsets = np.ma.column_stack([x, y])

# If orig_facecolors is 'none' and we're using colormapping (colors is None),
# then we need to map colors to edges instead of faces
if colors is None and cbook._str_lower_equal(orig_facecolors, 'none'):
facecolors_for_collection = 'none'
# Set edgecolors to None to allow color mapping to edges
# (unless the user explicitly set edgecolors)
if orig_edgecolor is None:
edgecolors = None
else:
facecolors_for_collection = colors

collection = mcoll.PathCollection(
(path,), scales,
facecolors=colors,
facecolors=facecolors_for_collection,
edgecolors=edgecolors,
linewidths=linewidths,
offsets=offsets,
Expand Down
108 changes: 18 additions & 90 deletionslib/matplotlib/collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -379,24 +379,20 @@
from matplotlib.patheffects import PathEffectRenderer
renderer = PathEffectRenderer(self.get_path_effects(), renderer)

# If the collection is made up of a single shape/color/stroke,
# it can be rendered once and blitted multiple times, using
# `draw_markers` rather than `draw_path_collection`. This is
# *much* faster for Agg, and results in smaller file sizes in
# PDF/SVG/PS.

trans = self.get_transforms()
# Get facecolors and edgecolors
facecolors = self.get_facecolor()
edgecolors = self.get_edgecolor()

# Single path optimization
do_single_path_optimization = False
if (len(paths) == 1 and len(trans) <= 1 and
if (len(paths) == 1 and len(self.get_transforms()) <= 1 and
len(facecolors) == 1 and len(edgecolors) == 1 and
len(self._linewidths) == 1 and
all(ls[1] is None for ls in self._linestyles) and
len(self._antialiaseds) == 1 and len(self._urls) == 1 and
self.get_hatch() is None):
if len(trans):
combined_transform = transforms.Affine2D(trans[0]) + transform
if len(self.get_transforms()):
combined_transform = transforms.Affine2D(self.get_transforms()[0]) + transform

Check warning on line 395 in lib/matplotlib/collections.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Line too long (94 > 88)Raw Output:message:"Line too long (94 > 88)" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/collections.py" range:{start:{line:395 column:89} end:{line:395 column:95}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E501" url:"https://docs.astral.sh/ruff/rules/line-too-long"}
else:
combined_transform = transform
extents = paths[0].get_extents(combined_transform)
Expand All@@ -420,86 +416,12 @@
gc, paths[0], combined_transform.frozen(),
mpath.Path(offsets), offset_trf, tuple(facecolors[0]))
else:
# The current new API of draw_path_collection() is provisional
# and will be changed in a future PR.

# Find whether renderer.draw_path_collection() takes hatchcolor parameter.
# Since third-party implementations of draw_path_collection() may not be
# introspectable, e.g. with inspect.signature, the only way is to try and
# call this with the hatchcolors parameter.
hatchcolors_arg_supported = True
try:
renderer.draw_path_collection(
gc, transform.frozen(), [],
self.get_transforms(), offsets, offset_trf,
self.get_facecolor(), self.get_edgecolor(),
self._linewidths, self._linestyles,
self._antialiaseds, self._urls,
"screen", hatchcolors=self.get_hatchcolor()
)
except TypeError:
# If the renderer does not support the hatchcolors argument,
# it will raise a TypeError. In this case, we will
# iterate over all paths and draw them one by one.
hatchcolors_arg_supported = False

# If the hatchcolors argument is not needed or not passed
# then we can skip the iteration over paths in case the
# argument is not supported by the renderer.
hatchcolors_not_needed = (self.get_hatch() is None or
self._original_hatchcolor is None)

if self._gapcolor is not None:
# First draw paths within the gaps.
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
args = [offsets, offset_trf, [mcolors.to_rgba("none")], self._gapcolor,
self._linewidths, ilinestyles, self._antialiaseds, self._urls,
"screen"]

if hatchcolors_arg_supported:
renderer.draw_path_collection(gc, transform.frozen(), ipaths,
self.get_transforms(), *args,
hatchcolors=self.get_hatchcolor())
else:
if hatchcolors_not_needed:
renderer.draw_path_collection(gc, transform.frozen(), ipaths,
self.get_transforms(), *args)
else:
path_ids = renderer._iter_collection_raw_paths(
transform.frozen(), ipaths, self.get_transforms())
for xo, yo, path_id, gc0, rgbFace in renderer._iter_collection(
gc, list(path_ids), *args,
hatchcolors=self.get_hatchcolor(),
):
path, transform = path_id
if xo != 0 or yo != 0:
transform = transform.frozen()
transform.translate(xo, yo)
renderer.draw_path(gc0, path, transform, rgbFace)

args = [offsets, offset_trf, self.get_facecolor(), self.get_edgecolor(),
args = [offsets, offset_trf, facecolors, edgecolors,
self._linewidths, self._linestyles, self._antialiaseds, self._urls,
"screen"]

if hatchcolors_arg_supported:
renderer.draw_path_collection(gc, transform.frozen(), paths,
self.get_transforms(), *args,
hatchcolors=self.get_hatchcolor())
else:
if hatchcolors_not_needed:
renderer.draw_path_collection(gc, transform.frozen(), paths,
self.get_transforms(), *args)
else:
path_ids = renderer._iter_collection_raw_paths(
transform.frozen(), paths, self.get_transforms())
for xo, yo, path_id, gc0, rgbFace in renderer._iter_collection(
gc, list(path_ids), *args, hatchcolors=self.get_hatchcolor(),
):
path, transform = path_id
if xo != 0 or yo != 0:
transform = transform.frozen()
transform.translate(xo, yo)
renderer.draw_path(gc0, path, transform, rgbFace)
renderer.draw_path_collection(gc, transform.frozen(), paths,
self.get_transforms(), *args)

gc.restore()
renderer.close_group(self.__class__.__name__)
Expand DownExpand Up@@ -836,7 +758,11 @@
if c is None:
c = self._get_default_facecolor()

self._facecolors = mcolors.to_rgba_array(c, self._alpha)
# Explicit handling for 'none'
if isinstance(c, str) and c.lower() == 'none':
self._facecolors = np.zeros((0, 4)) # No fill
else:
self._facecolors = mcolors.to_rgba_array(c, self._alpha)
self.stale = True

def set_facecolor(self, c):
Expand All@@ -851,6 +777,8 @@
----------
c : :mpltype:`color` or list of :mpltype:`color`
"""
if c is None and self._original_facecolor is not None:
c = self._original_facecolor
if isinstance(c, str) and c.lower() in ("none", "face"):
c = c.lower()
self._original_facecolor = c
Expand DownExpand Up@@ -999,9 +927,9 @@
"""
if not self._set_mappable_flags():
return
# Allow possibility to call 'self.set_array(None)'.

if self._A is not None:
# QuadMesh can map2d arrays (but pcolormeshsupplies 1d array)
# QuadMesh can map2D arrays (but pcolormeshprovides 1D array)
if self._A.ndim > 1 and not isinstance(self, _MeshData):
raise ValueError('Collections can only map rank 1 arrays')
if np.iterable(self._alpha):
Expand Down
1 change: 1 addition & 0 deletionslib/matplotlib/pyplot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4073,6 +4073,7 @@ def scatter(
data=None,
**kwargs,
) -> PathCollection:
# print(f"scatter called with facecolors: {facecolors}") # Adicionado para teste
__ret = gca().scatter(
x,
y,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp