@@ -272,6 +272,7 @@ def __init__(self, xdata, ydata,
272
272
linewidth = None , # all Nones default to rc
273
273
linestyle = None ,
274
274
color = None ,
275
+ secondcolor = None ,
275
276
marker = None ,
276
277
markersize = None ,
277
278
markeredgewidth = None ,
@@ -364,6 +365,9 @@ def __init__(self, xdata, ydata,
364
365
else :
365
366
self ._marker = marker
366
367
368
+ self ._secondcolor = None
369
+ self .set_secondcolor (secondcolor )
370
+
367
371
self ._markevery = None
368
372
self ._markersize = None
369
373
self ._antialiased = None
@@ -754,9 +758,6 @@ def draw(self, renderer):
754
758
self ._set_gc_clip (gc )
755
759
gc .set_url (self .get_url ())
756
760
757
- lc_rgba = mcolors .to_rgba (self ._color , self ._alpha )
758
- gc .set_foreground (lc_rgba , isRGBA = True )
759
-
760
761
gc .set_antialiased (self ._antialiased )
761
762
gc .set_linewidth (self ._linewidth )
762
763
@@ -772,6 +773,26 @@ def draw(self, renderer):
772
773
if self .get_sketch_params () is not None :
773
774
gc .set_sketch_params (* self .get_sketch_params ())
774
775
776
+ # We first draw a path within the gaps if needed.
777
+ if self .is_dashed () and self ._secondcolor is not None :
778
+ lc_rgba = mcolors .to_rgba (self ._secondcolor , self ._alpha )
779
+ gc .set_foreground (lc_rgba , isRGBA = True )
780
+
781
+ # Define the inverse pattern by moving the last gap to the
782
+ # start of the sequence.
783
+ dashes = self ._dash_pattern [1 ]
784
+ gaps = dashes [- 1 :] + dashes [:- 1 ]
785
+ # Set the offset so that this new first segment is skipped
786
+ # (see backend_bases.GraphicsContextBase.set_dashes for
787
+ # offset definition).
788
+ offset_gaps = self ._dash_pattern [0 ] + dashes [- 1 ]
789
+
790
+ gc .set_dashes (offset_gaps , gaps )
791
+ renderer .draw_path (gc , tpath , affine .frozen ())
792
+
793
+ lc_rgba = mcolors .to_rgba (self ._color , self ._alpha )
794
+ gc .set_foreground (lc_rgba , isRGBA = True )
795
+
775
796
gc .set_dashes (* self ._dash_pattern )
776
797
renderer .draw_path (gc , tpath , affine .frozen ())
777
798
gc .restore ()
@@ -868,6 +889,14 @@ def get_color(self):
868
889
"""
869
890
return self ._color
870
891
892
+ def get_secondcolor (self ):
893
+ """
894
+ Return the line secondcolor.
895
+
896
+ See also `~.Line2D.set_secondcolor`.
897
+ """
898
+ return self ._secondcolor
899
+
871
900
def get_drawstyle (self ):
872
901
"""
873
902
Return the drawstyle.
@@ -1031,6 +1060,25 @@ def set_color(self, color):
1031
1060
self ._color = color
1032
1061
self .stale = True
1033
1062
1063
+ def set_secondcolor (self , secondcolor ):
1064
+ """
1065
+ Set a second color to fill the gaps in the dashed line style.
1066
+
1067
+ .. warning::
1068
+
1069
+ In some cases the two line colors may overlap, which could lead to
1070
+ unwanted effects if also setting ``alpha``.
1071
+
1072
+ Parameters
1073
+ ----------
1074
+ secondcolor : color or None
1075
+ The second color. If None, the gaps are unfilled.
1076
+ """
1077
+ if secondcolor is not None :
1078
+ mcolors ._check_color_like (color = secondcolor )
1079
+ self ._secondcolor = secondcolor
1080
+ self .stale = True
1081
+
1034
1082
def set_drawstyle (self , drawstyle ):
1035
1083
"""
1036
1084
Set the drawstyle of the plot.
@@ -1264,6 +1312,7 @@ def update_from(self, other):
1264
1312
self ._linestyle = other ._linestyle
1265
1313
self ._linewidth = other ._linewidth
1266
1314
self ._color = other ._color
1315
+ self ._secondcolor = other ._secondcolor
1267
1316
self ._markersize = other ._markersize
1268
1317
self ._markerfacecolor = other ._markerfacecolor
1269
1318
self ._markerfacecoloralt = other ._markerfacecoloralt
0 commit comments