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

Commita185a2a

Browse files
committed
Rebasing on master.
1 parentcd1ae80 commita185a2a

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

‎lib/matplotlib/collections.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,26 @@ def set_edgecolor(self, c):
735735
defset_alpha(self,alpha):
736736
"""
737737
Set the alpha tranparencies of the collection. *alpha* must be
738-
a float or *None*.
738+
a float, a sequence of floats matching an array to be
739+
colormapped, or *None*.
739740
740741
ACCEPTS: float or None
741742
"""
742743
ifalphaisnotNone:
743-
try:
744-
float(alpha)
745-
exceptTypeError:
746-
raiseTypeError('alpha must be a float or None')
747-
self.update_dict['array']=True
744+
ifcbook.iterable(alpha):
745+
alpha=np.asarray(alpha,dtype=float)
746+
alphatype='array'
747+
else:
748+
try:
749+
float(alpha)
750+
alphatype='scalar'
751+
exceptTypeError:
752+
raiseTypeError('alpha must be a float,'
753+
' sequence of float, or None')
748754
artist.Artist.set_alpha(self,alpha)
755+
self.update_dict['array']=True
756+
ifalphaisnotNoneandalphatype=='array':
757+
return
749758
self._set_facecolor(self._original_facecolor)
750759
self._set_edgecolor(self._original_edgecolor)
751760

‎lib/matplotlib/colors.py‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,9 @@ def __call__(self, X, alpha=None, bytes=False):
457457
return the RGBA values ``X*100`` percent along the Colormap line.
458458
For integers, X should be in the interval ``[0, Colormap.N)`` to
459459
return RGBA values *indexed* from the Colormap with index ``X``.
460-
alpha : float, None
461-
Alpha must be a scalar between 0 and 1, or None.
460+
alpha : float, array-like, None
461+
Alpha must be a scalar between 0 and 1, a sequence of such
462+
floats with shape matching X, or None.
462463
bytes : bool
463464
If False (default), the returned RGBA values will be floats in the
464465
interval ``[0, 1]`` otherwise they will be uint8s in the interval
@@ -484,6 +485,26 @@ def __call__(self, X, alpha=None, bytes=False):
484485
xa=xma.filled()# Fill to avoid infs, etc.
485486
delxma
486487

488+
ifalphaisnotNone:
489+
ifnotcbook.iterable(alpha):
490+
alphatype='scalar'
491+
ifalpha<0oralpha>1:
492+
raiseValueError("alpha must be in [0, 1];"
493+
" found %s"%alpha)
494+
else:
495+
alphatype='array'
496+
alpha=np.asarray(alpha)
497+
_mina=alpha.min()
498+
_maxa=alpha.max()
499+
if_mina<0or_maxa>1:
500+
raiseValueError("alpha must be in [0, 1];"
501+
" found min %s and max %s"%
502+
(_mina,_maxa))
503+
ifnot (alpha.shape==xa.shape):
504+
raiseValueError("alpha is array-like but it's shape"
505+
" %s doesn't match that of X %s"%
506+
(alpha.shape,xa.shape))
507+
487508
# Calculations with native byteorder are faster, and avoid a
488509
# bug that otherwise can occur with putmask when the last
489510
# argument is a numpy scalar.
@@ -514,7 +535,7 @@ def __call__(self, X, alpha=None, bytes=False):
514535
else:
515536
lut=self._lut.copy()# Don't let alpha modify original _lut.
516537

517-
ifalphaisnotNone:
538+
ifalphaisnotNoneandalphatype=='scalar':
518539
alpha=np.clip(alpha,0,1)
519540
ifbytes:
520541
alpha=int(alpha*255)
@@ -530,6 +551,17 @@ def __call__(self, X, alpha=None, bytes=False):
530551

531552
rgba=np.empty(shape=xa.shape+ (4,),dtype=lut.dtype)
532553
lut.take(xa,axis=0,mode='clip',out=rgba)
554+
555+
ifalphaisnotNoneandalphatype=='array':
556+
ifbytes:
557+
alpha= (alpha*255).astype(np.uint8)
558+
rgba[...,-1]=alpha
559+
if (lut[-1]==0).all()andmask_badisnotNone:
560+
ifmask_bad.shape==xa.shape:
561+
rgba[mask_bad]= (0,0,0,0)
562+
elifmask_bad:
563+
rgba[..., :]= (0,0,0,0)
564+
533565
ifvtype=='scalar':
534566
rgba=tuple(rgba[0, :])
535567
returnrgba

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp