28
28
"antialiased" : ["antialiaseds" , "aa" ],
29
29
"edgecolor" : ["edgecolors" , "ec" ],
30
30
"facecolor" : ["facecolors" , "fc" ],
31
- "linestyle" : ["linestyles" , "dashes" , " ls" ],
31
+ "linestyle" : ["linestyles" , "ls" ],
32
32
"linewidth" : ["linewidths" , "lw" ],
33
33
"offset_transform" : ["transOffset" ],
34
34
})
@@ -79,7 +79,7 @@ def __init__(self, *,
79
79
edgecolors = None ,
80
80
facecolors = None ,
81
81
linewidths = None ,
82
- linestyles = 'solid ' ,
82
+ linestyles = '- ' ,
83
83
capstyle = None ,
84
84
joinstyle = None ,
85
85
antialiaseds = None ,
@@ -104,15 +104,8 @@ def __init__(self, *,
104
104
Face color for each patch making up the collection.
105
105
linewidths : float or list of floats, default: :rc:`patch.linewidth`
106
106
Line width for each patch making up the collection.
107
- linestyles : str or tuple or list thereof, default: 'solid'
108
- Valid strings are ['solid', 'dashed', 'dashdot', 'dotted', '-',
109
- '--', '-.', ':']. Dash tuples should be of the form::
110
-
111
- (offset, onoffseq),
112
-
113
- where *onoffseq* is an even length tuple of on and off ink lengths
114
- in points. For examples, see
115
- :doc:`/gallery/lines_bars_and_markers/linestyles`.
107
+ linestyles : str or tuple or list thereof, default: '-'
108
+ Line style or list of line styles. See `set_linestyle` for details.
116
109
capstyle : `.CapStyle`-like, default: :rc:`patch.capstyle`
117
110
Style to use for capping lines for all paths in the collection.
118
111
Allowed values are %(CapStyle)s.
@@ -156,11 +149,12 @@ def __init__(self, *,
156
149
cm .ScalarMappable .__init__ (self , norm , cmap )
157
150
# list of un-scaled dash patterns
158
151
# this is needed scaling the dash pattern by linewidth
159
- self ._us_linestyles = [(0 , None )]
152
+ self ._unscaled_dash_patterns = [(0 , None )]
160
153
# list of dash patterns
161
- self ._linestyles = [(0 , None )]
154
+ self ._dash_patterns = [(0 , None )]
155
+ self ._linestyles = ['-' ]
162
156
# list of unbroadcast/scaled linewidths
163
- self ._us_lw = [0 ]
157
+ self ._unscaled_lw = [0 ]
164
158
self ._linewidths = [0 ]
165
159
166
160
self ._gapcolor = None # Currently only used by LineCollection.
@@ -379,7 +373,7 @@ def draw(self, renderer):
379
373
if (len (paths ) == 1 and len (trans ) <= 1 and
380
374
len (facecolors ) == 1 and len (edgecolors ) == 1 and
381
375
len (self ._linewidths ) == 1 and
382
- all (ls [1 ] is None for ls in self ._linestyles ) and
376
+ all (dash [1 ] is None for dash in self ._dash_patterns ) and
383
377
len (self ._antialiaseds ) == 1 and len (self ._urls ) == 1 and
384
378
self .get_hatch () is None ):
385
379
if len (trans ):
@@ -400,7 +394,7 @@ def draw(self, renderer):
400
394
if do_single_path_optimization :
401
395
gc .set_foreground (tuple (edgecolors [0 ]))
402
396
gc .set_linewidth (self ._linewidths [0 ])
403
- gc .set_dashes (* self ._linestyles [0 ])
397
+ gc .set_dashes (* self ._dash_patterns [0 ])
404
398
gc .set_antialiased (self ._antialiaseds [0 ])
405
399
gc .set_url (self ._urls [0 ])
406
400
renderer .draw_markers (
@@ -422,7 +416,7 @@ def draw(self, renderer):
422
416
gc , transform .frozen (), paths ,
423
417
self .get_transforms (), offsets , offset_trf ,
424
418
self .get_facecolor (), self .get_edgecolor (),
425
- self ._linewidths , self ._linestyles ,
419
+ self ._linewidths , self ._dash_patterns ,
426
420
self ._antialiaseds , self ._urls ,
427
421
"screen" ) # offset_position, kept for backcompat.
428
422
@@ -579,54 +573,77 @@ def set_linewidth(self, lw):
579
573
if lw is None :
580
574
lw = self ._get_default_linewidth ()
581
575
# get the un-scaled/broadcast lw
582
- self ._us_lw = np .atleast_1d (lw )
576
+ self ._unscaled_lw = np .atleast_1d (lw )
583
577
584
578
# scale all of the dash patterns.
585
- self ._linewidths , self ._linestyles = self ._bcast_lwls (
586
- self ._us_lw , self ._us_linestyles )
579
+ self ._linewidths , self ._dash_patterns = self ._bcast_lwls (
580
+ self ._unscaled_lw , self ._unscaled_dash_patterns )
587
581
self .stale = True
588
582
589
583
def set_linestyle (self , ls ):
590
584
"""
591
- Set the linestyle(s) for the collection.
585
+ Set the line style(s) for the collection.
586
+
587
+ Parameters
588
+ ----------
589
+ ls : str or tuple or list thereof
590
+ The line style. Possible values:
592
591
593
- =========================== =================
594
- linestyle description
595
- =========================== =================
596
- ``'-'`` or ``'solid'`` solid line
597
- ``'--'`` or ``'dashed'`` dashed line
598
- ``'-.'`` or ``'dashdot'`` dash-dotted line
599
- ``':'`` or ``'dotted'`` dotted line
600
- =========================== =================
592
+ - A string:
601
593
602
- Alternatively a dash tuple of the following form can be provided::
594
+ ========================================== =================
595
+ linestyle description
596
+ ========================================== =================
597
+ ``'-'`` or ``'solid'`` solid line
598
+ ``'--'`` or ``'dashed'`` dashed line
599
+ ``'-.'`` or ``'dashdot'`` dash-dotted line
600
+ ``':'`` or ``'dotted'`` dotted line
601
+ ``'none'``, ``'None'``, ``' '``, or ``''`` draw nothing
602
+ ========================================== =================
603
603
604
- (offset, onoffseq),
604
+ - Alternatively a dash tuple of the following form can be
605
+ provided::
605
606
606
- where ``onoffseq`` is an even length tuple of on and off ink in points.
607
+ (offset, onoffseq)
607
608
608
- Parameters
609
- ----------
610
- ls : str or tuple or list thereof
611
- Valid values for individual linestyles include {'-', '--', '-.',
612
- ':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
613
- complete description.
609
+ where ``onoffseq`` is an even length tuple of on and off ink
610
+ in points.
611
+
612
+ If a single value is provided, this applies to all objects in the
613
+ collection. A list can be provided to set different line styles to
614
+ different objects.
615
+
616
+ For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
617
+
618
+ The ``'dashed'``, ``'dashdot'``, and ``'dotted'`` line styles are
619
+ controlled by :rc:`lines.dashed_pattern`,
620
+ :rc:`lines.dashdot_pattern`, and :rc:`lines.dotted_pattern`,
621
+ respectively.
614
622
"""
615
- try :
616
- dashes = [ mlines ._get_dash_pattern (ls )]
617
- except ValueError :
623
+ if isinstance ( ls , str ) :
624
+ dashes , ls_norm = map ( list , zip ( mlines ._get_dash_pattern (ls )))
625
+ else :
618
626
try :
619
- dashes = [ mlines ._get_dash_pattern (x ) for x in ls ]
620
- except ValueError as err :
621
- emsg = f'Do not know how to convert { ls !r } to dashes'
622
- raise ValueError ( emsg ) from err
627
+ dashes , ls_norm = map ( list , zip ( mlines ._get_dash_pattern (ls )))
628
+ except ValueError :
629
+ dashes , ls_norm = map (
630
+ list , zip ( * [ mlines . _get_dash_pattern ( x ) for x in ls ]))
623
631
624
632
# get the list of raw 'unscaled' dash patterns
625
- self ._us_linestyles = dashes
633
+ self ._unscaled_dash_patterns = dashes
626
634
627
635
# broadcast and scale the lw and dash patterns
628
- self ._linewidths , self ._linestyles = self ._bcast_lwls (
629
- self ._us_lw , self ._us_linestyles )
636
+ self ._linewidths , self ._dash_patterns = self ._bcast_lwls (
637
+ self ._unscaled_lw , self ._unscaled_dash_patterns )
638
+ self ._linestyles = ls_norm
639
+
640
+ def get_dashes (self ):
641
+ """
642
+ Return the dash patterns.
643
+
644
+ .. versionadded:: 3.8
645
+ """
646
+ return self ._dash_patterns
630
647
631
648
@_docstring .interpd
632
649
def set_capstyle (self , cs ):
@@ -918,8 +935,10 @@ def update_from(self, other):
918
935
self ._original_facecolor = other ._original_facecolor
919
936
self ._facecolors = other ._facecolors
920
937
self ._linewidths = other ._linewidths
938
+ self ._unscaled_lw = other ._unscaled_lw
921
939
self ._linestyles = other ._linestyles
922
- self ._us_linestyles = other ._us_linestyles
940
+ self ._unscaled_dash_patterns = other ._unscaled_dash_patterns
941
+ self ._dash_patterns = other ._dash_patterns
923
942
self ._pickradius = other ._pickradius
924
943
self ._hatch = other ._hatch
925
944
@@ -1555,7 +1574,7 @@ def __init__(self,
1555
1574
linelength = 1 ,
1556
1575
linewidth = None ,
1557
1576
color = None ,
1558
- linestyle = 'solid ' ,
1577
+ linestyle = '- ' ,
1559
1578
antialiased = None ,
1560
1579
** kwargs
1561
1580
):
@@ -1578,14 +1597,8 @@ def __init__(self,
1578
1597
The line width of the event lines, in points.
1579
1598
color : color or list of colors, default: :rc:`lines.color`
1580
1599
The color of the event lines.
1581
- linestyle : str or tuple or list thereof, default: 'solid'
1582
- Valid strings are ['solid', 'dashed', 'dashdot', 'dotted',
1583
- '-', '--', '-.', ':']. Dash tuples should be of the form::
1584
-
1585
- (offset, onoffseq),
1586
-
1587
- where *onoffseq* is an even length tuple of on and off ink
1588
- in points.
1600
+ linestyle : str or tuple or list thereof, default: '-'
1601
+ Line style or list of line styles. See `set_linestyle` for details.
1589
1602
antialiased : bool or list thereof, default: :rc:`lines.antialiased`
1590
1603
Whether to use antialiasing for drawing the lines.
1591
1604
**kwargs
0 commit comments