@@ -273,6 +273,7 @@ def __init__(self, xdata, ydata,
273
273
linewidth = None , # all Nones default to rc
274
274
linestyle = None ,
275
275
color = None ,
276
+ gapcolor = None ,
276
277
marker = None ,
277
278
markersize = None ,
278
279
markeredgewidth = None ,
@@ -365,6 +366,9 @@ def __init__(self, xdata, ydata,
365
366
else :
366
367
self ._marker = marker
367
368
369
+ self ._gapcolor = None
370
+ self .set_gapcolor (gapcolor )
371
+
368
372
self ._markevery = None
369
373
self ._markersize = None
370
374
self ._antialiased = None
@@ -755,9 +759,6 @@ def draw(self, renderer):
755
759
self ._set_gc_clip (gc )
756
760
gc .set_url (self .get_url ())
757
761
758
- lc_rgba = mcolors .to_rgba (self ._color , self ._alpha )
759
- gc .set_foreground (lc_rgba , isRGBA = True )
760
-
761
762
gc .set_antialiased (self ._antialiased )
762
763
gc .set_linewidth (self ._linewidth )
763
764
@@ -773,6 +774,26 @@ def draw(self, renderer):
773
774
if self .get_sketch_params () is not None :
774
775
gc .set_sketch_params (* self .get_sketch_params ())
775
776
777
+ # We first draw a path within the gaps if needed.
778
+ if self .is_dashed () and self ._gapcolor is not None :
779
+ lc_rgba = mcolors .to_rgba (self ._gapcolor , self ._alpha )
780
+ gc .set_foreground (lc_rgba , isRGBA = True )
781
+
782
+ # Define the inverse pattern by moving the last gap to the
783
+ # start of the sequence.
784
+ dashes = self ._dash_pattern [1 ]
785
+ gaps = dashes [- 1 :] + dashes [:- 1 ]
786
+ # Set the offset so that this new first segment is skipped
787
+ # (see backend_bases.GraphicsContextBase.set_dashes for
788
+ # offset definition).
789
+ offset_gaps = self ._dash_pattern [0 ] + dashes [- 1 ]
790
+
791
+ gc .set_dashes (offset_gaps , gaps )
792
+ renderer .draw_path (gc , tpath , affine .frozen ())
793
+
794
+ lc_rgba = mcolors .to_rgba (self ._color , self ._alpha )
795
+ gc .set_foreground (lc_rgba , isRGBA = True )
796
+
776
797
gc .set_dashes (* self ._dash_pattern )
777
798
renderer .draw_path (gc , tpath , affine .frozen ())
778
799
gc .restore ()
@@ -877,6 +898,14 @@ def get_drawstyle(self):
877
898
"""
878
899
return self ._drawstyle
879
900
901
+ def get_gapcolor (self ):
902
+ """
903
+ Return the line gapcolor.
904
+
905
+ See also `~.Line2D.set_gapcolor`.
906
+ """
907
+ return self ._gapcolor
908
+
880
909
def get_linestyle (self ):
881
910
"""
882
911
Return the linestyle.
@@ -1067,6 +1096,29 @@ def set_drawstyle(self, drawstyle):
1067
1096
self ._invalidx = True
1068
1097
self ._drawstyle = drawstyle
1069
1098
1099
+ def set_gapcolor (self , gapcolor ):
1100
+ """
1101
+ Set a color to fill the gaps in the dashed line style.
1102
+
1103
+ .. note::
1104
+
1105
+ Striped lines are created by drawing two interleaved dashed lines.
1106
+ There can be overlaps between those two, which may result in
1107
+ artifacts when using transparency.
1108
+
1109
+ This functionality is experimental and may change.
1110
+
1111
+ Parameters
1112
+ ----------
1113
+ gapcolor : color or None
1114
+ The color with which to fill the gaps. If None, the gaps are
1115
+ unfilled.
1116
+ """
1117
+ if gapcolor is not None :
1118
+ mcolors ._check_color_like (color = gapcolor )
1119
+ self ._gapcolor = gapcolor
1120
+ self .stale = True
1121
+
1070
1122
def set_linewidth (self , w ):
1071
1123
"""
1072
1124
Set the line width in points.
@@ -1248,6 +1300,9 @@ def set_dashes(self, seq):
1248
1300
For example, (5, 2, 1, 2) describes a sequence of 5 point and 1 point
1249
1301
dashes separated by 2 point spaces.
1250
1302
1303
+ See also `~.Line2D.set_gapcolor`, which allows those spaces to be
1304
+ filled with a color.
1305
+
1251
1306
Parameters
1252
1307
----------
1253
1308
seq : sequence of floats (on/off ink in points) or (None, None)
@@ -1265,6 +1320,7 @@ def update_from(self, other):
1265
1320
self ._linestyle = other ._linestyle
1266
1321
self ._linewidth = other ._linewidth
1267
1322
self ._color = other ._color
1323
+ self ._gapcolor = other ._gapcolor
1268
1324
self ._markersize = other ._markersize
1269
1325
self ._markerfacecolor = other ._markerfacecolor
1270
1326
self ._markerfacecoloralt = other ._markerfacecoloralt
0 commit comments