19
19
import warnings
20
20
21
21
22
+ # "color" is excluded; it is a compound setter, and its docstring differs
23
+ # in LineCollection.
22
24
@cbook ._define_aliases ({
23
25
"antialiased" : ["antialiaseds" , "aa" ],
24
26
"edgecolor" : ["edgecolors" , "ec" ],
@@ -589,6 +591,13 @@ def get_offset_position(self):
589
591
"""
590
592
return self ._offset_position
591
593
594
+ def _get_default_linewidth (self ):
595
+ # This may be overridden in a subclass.
596
+ lw = mpl .rcParams ['patch.linewidth' ]
597
+ if lw is None :
598
+ lw = mpl .rcParams ['lines.linewidth' ]
599
+ return lw
600
+
592
601
def set_linewidth (self , lw ):
593
602
"""
594
603
Set the linewidth(s) for the collection. *lw* can be a scalar
@@ -600,9 +609,7 @@ def set_linewidth(self, lw):
600
609
lw : float or list of floats
601
610
"""
602
611
if lw is None :
603
- lw = mpl .rcParams ['patch.linewidth' ]
604
- if lw is None :
605
- lw = mpl .rcParams ['lines.linewidth' ]
612
+ lw = self ._get_default_linewidth ()
606
613
# get the un-scaled/broadcast lw
607
614
self ._us_lw = np .atleast_1d (np .asarray (lw ))
608
615
@@ -755,9 +762,13 @@ def set_color(self, c):
755
762
self .set_facecolor (c )
756
763
self .set_edgecolor (c )
757
764
765
+ def _get_default_facecolor (self ):
766
+ # This may be overridden in a subclass.
767
+ return mpl .rcParams ['patch.facecolor' ]
768
+
758
769
def _set_facecolor (self , c ):
759
770
if c is None :
760
- c = mpl . rcParams [ 'patch.facecolor' ]
771
+ c = self . _get_default_facecolor ()
761
772
762
773
self ._facecolors = mcolors .to_rgba_array (c , self ._alpha )
763
774
self .stale = True
@@ -789,6 +800,7 @@ def get_edgecolor(self):
789
800
return self ._edgecolors
790
801
791
802
def _get_default_edgecolor (self ):
803
+ # This may be overridden in a subclass.
792
804
return mpl .rcParams ['patch.edgecolor' ]
793
805
794
806
def _set_edgecolor (self , c ):
@@ -799,7 +811,7 @@ def _set_edgecolor(self, c):
799
811
else :
800
812
c = 'none'
801
813
set_hatch_color = False
802
- if isinstance (c , str ) and c == 'face' :
814
+ if cbook . _str_lower_equal (c , 'face' ) :
803
815
self ._edgecolors = 'face'
804
816
self .stale = True
805
817
return
@@ -852,32 +864,46 @@ def get_linestyle(self):
852
864
return self ._linestyles
853
865
854
866
def _set_mappable_flags (self ):
867
+ """
868
+ Determine whether edges and/or faces are color-mapped.
869
+
870
+ This is a helper for update_scalarmappable.
871
+ It sets Boolean flags '_edge_is_mapped' and '_face_is_mapped'.
872
+
873
+ Returns
874
+ -------
875
+ mapping_change: bool
876
+ True if either flag is True, or if a flag has changed.
877
+ """
855
878
edge0 = self ._edge_is_mapped
856
879
face0 = self ._face_is_mapped
857
880
if self ._A is None :
858
881
self ._edge_is_mapped = False
859
882
self ._face_is_mapped = False
860
- # return False # Nothing to map
861
883
else :
862
- # Typical mapping: centers , not edges.
884
+ # Typical mapping: faces , not edges.
863
885
self ._face_is_mapped = True
864
886
self ._edge_is_mapped = False
865
887
866
- # Make the colors None or a string. (If None, it is a default.)
888
+ # Prepare color strings to check for special cases.
867
889
fc = self ._original_facecolor
868
- if not (fc is None or isinstance (fc , str )):
890
+ if fc is None :
891
+ fc = self ._get_default_facecolor ()
892
+ if not isinstance (fc , str ):
869
893
fc = 'array'
870
894
ec = self ._original_edgecolor
871
- if not (ec is None or isinstance (ec , str )):
895
+ if ec is None :
896
+ ec = self ._get_default_edgecolor ()
897
+ if not isinstance (ec , str ):
872
898
ec = 'array'
873
899
874
900
# Handle special cases.
875
901
if fc == 'none' :
876
902
self ._face_is_mapped = False
877
- if ec in ( 'face' , 'none' , None ):
878
- self . _edge_is_mapped = True
879
- if ec == 'face' :
880
- self ._edge_is_mapped = self . _face_is_mapped
903
+ self . _edge_is_mapped = True
904
+ elif ec == 'face' :
905
+ self . _edge_is_mapped = True
906
+ self ._face_is_mapped = True
881
907
882
908
mapped = self ._face_is_mapped or self ._edge_is_mapped
883
909
changed = (self ._edge_is_mapped != edge0
@@ -924,8 +950,7 @@ def update_scalarmappable(self):
924
950
925
951
def get_fill (self ):
926
952
"""Return whether face is colored."""
927
- fill = not (isinstance (self ._original_facecolor , str )
928
- and self ._original_facecolor == "none" )
953
+ fill = not cbook ._str_lower_equal (self ._original_facecolor , "none" )
929
954
return fill
930
955
931
956
def update_from (self , other ):
@@ -1394,18 +1419,8 @@ class LineCollection(Collection):
1394
1419
1395
1420
_edge_default = True
1396
1421
1397
- def __init__ (self , segments , # Can be None.
1398
- linewidths = None ,
1399
- colors = None ,
1400
- antialiaseds = None ,
1401
- linestyles = 'solid' ,
1402
- offsets = None ,
1403
- transOffset = None ,
1404
- norm = None ,
1405
- cmap = None ,
1406
- pickradius = 5 ,
1407
- zorder = 2 ,
1408
- facecolors = 'none' ,
1422
+ def __init__ (self , segments , # Can be None.
1423
+ zorder = 2 , # Collection.zorder is 1
1409
1424
** kwargs
1410
1425
):
1411
1426
"""
@@ -1439,29 +1454,11 @@ def __init__(self, segments, # Can be None.
1439
1454
**kwargs
1440
1455
Forwarded to `.Collection`.
1441
1456
"""
1442
- kw_plural = dict (linewidths = linewidths ,
1443
- colors = colors ,
1444
- facecolors = facecolors ,
1445
- antialiaseds = antialiaseds ,
1446
- linestyles = linestyles ,)
1447
-
1448
- kw = {k : kwargs .pop (k [:- 1 ], val ) for k , val in kw_plural .items ()}
1449
- kw .update (kwargs )
1450
- colors = kw .pop ('colors' )
1451
- if kw ['linewidths' ] is None :
1452
- kw ['linewidths' ] = (mpl .rcParams ['lines.linewidth' ],)
1453
- if kw ['antialiaseds' ] is None :
1454
- kw ['antialiaseds' ] = (mpl .rcParams ['lines.antialiased' ],)
1455
1457
1456
1458
super ().__init__ (
1457
- offsets = offsets ,
1458
- transOffset = transOffset ,
1459
- norm = norm ,
1460
- cmap = cmap ,
1461
1459
zorder = zorder ,
1462
- ** kw )
1460
+ ** kwargs )
1463
1461
self .set_segments (segments )
1464
- self .set_color (colors ) # sets edgecolors, including default
1465
1462
1466
1463
def set_segments (self , segments ):
1467
1464
if segments is None :
@@ -1512,12 +1509,18 @@ def _add_offsets(self, segs):
1512
1509
segs [i ] = segs [i ] + offsets [io :io + 1 ]
1513
1510
return segs
1514
1511
1512
+ def _get_default_linewidth (self ):
1513
+ return mpl .rcParams ['lines.linewidth' ]
1514
+
1515
1515
def _get_default_edgecolor (self ):
1516
1516
return mpl .rcParams ['lines.color' ]
1517
1517
1518
+ def _get_default_facecolor (self ):
1519
+ return 'none'
1520
+
1518
1521
def set_color (self , c ):
1519
1522
"""
1520
- Set the color (s) of the LineCollection.
1523
+ Set the edgecolor (s) of the LineCollection.
1521
1524
1522
1525
Parameters
1523
1526
----------
@@ -1528,6 +1531,8 @@ def set_color(self, c):
1528
1531
"""
1529
1532
self .set_edgecolor (c )
1530
1533
1534
+ set_colors = set_color
1535
+
1531
1536
def get_color (self ):
1532
1537
return self ._edgecolors
1533
1538
0 commit comments