Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71f86ab

Browse files
sanrishitimhoffm
andauthored
MNT: Normalize internal set_foreground calls to RGBA (#31119)
* MNT: Normalize internal set_foreground calls to RGBA (#31105) * Update lib/matplotlib/collections.py Co-authored-by: Tim Hoffmann <[email protected]> * MNT: Apply review suggestions from rcomer * MNT: Simplify edgecolor handling in _iter_collection * MNT: Normalize edgecolor via to_rgba in _iter_collection --------- Co-authored-by: Tim Hoffmann <[email protected]>
1 parent 30c8b8c commit 71f86ab

5 files changed

Lines changed: 11 additions & 8 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,12 @@ def cycle_or_default(seq, default=None):
411411
gc0.set_linewidth(lw)
412412
if Nlinestyles:
413413
gc0.set_dashes(*ls)
414-
if len(ec) == 4 and ec[3] == 0.0:
414+
ec_rgba = colors.to_rgba(ec)
415+
# Fully transparent edges are treated as "no stroke".
416+
if ec_rgba[3] == 0.0:
415417
gc0.set_linewidth(0)
416418
else:
417-
gc0.set_foreground(ec)
419+
gc0.set_foreground(ec_rgba, isRGBA=True)
418420
if Nhatchcolors:
419421
gc0.set_hatch_color(hc)
420422
if fc is not None and len(fc) == 4 and fc[3] == 0:

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def draw(self, renderer):
411411
gc.set_capstyle(self._capstyle)
412412

413413
if do_single_path_optimization:
414-
gc.set_foreground(tuple(edgecolors[0]))
414+
gc.set_foreground(tuple(edgecolors[0]), isRGBA=True)
415415
gc.set_linewidth(self._linewidths[0])
416416
gc.set_dashes(*self._linestyles[0])
417417
gc.set_antialiased(self._antialiaseds[0])

lib/matplotlib/patheffects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
269269
else:
270270
shadow_rgbFace = self._shadow_rgbFace
271271

272-
gc0.set_foreground("none")
272+
gc0.set_foreground(mcolors.to_rgba("none"), isRGBA=True)
273273
gc0.set_alpha(self._alpha)
274274
gc0.set_linewidth(0)
275275

@@ -331,7 +331,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
331331
else:
332332
shadow_rgbFace = self._shadow_color
333333

334-
gc0.set_foreground(shadow_rgbFace)
334+
gc0.set_foreground(mcolors.to_rgba(shadow_rgbFace), isRGBA=True)
335335
gc0.set_alpha(self._alpha)
336336

337337
gc0 = self._update_gc(gc0, self._gc)

lib/matplotlib/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import numpy as np
1212

1313
import matplotlib as mpl
14-
from . import _api, artist, cbook, _docstring
14+
from . import _api, artist, cbook, _docstring, colors as mcolors
1515
from .artist import Artist
1616
from .font_manager import FontProperties
1717
from .patches import FancyArrowPatch, FancyBboxPatch, Rectangle
@@ -864,7 +864,7 @@ def draw(self, renderer):
864864
self._bbox_patch.draw(renderer)
865865

866866
gc = renderer.new_gc()
867-
gc.set_foreground(self.get_color())
867+
gc.set_foreground(mcolors.to_rgba(self.get_color()), isRGBA=True)
868868
gc.set_alpha(self.get_alpha())
869869
gc.set_url(self._url)
870870
gc.set_antialiased(self._antialiased)

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def draw(self, renderer):
178178
return
179179

180180
gc = renderer.new_gc()
181-
gc.set_foreground(self.get_markeredgecolor())
181+
edgecolor = mcolors.to_rgba(self.get_markeredgecolor())
182+
gc.set_foreground(edgecolor, isRGBA=True)
182183
gc.set_linewidth(self.get_markeredgewidth())
183184
gc.set_alpha(self._alpha)
184185

0 commit comments

Comments
 (0)