@@ -97,9 +97,10 @@ def __init__(self,
9797 else :
9898 self .set_edgecolor (edgecolor )
9999 self .set_facecolor (facecolor )
100- # unscaled dashes. Needed to scale dash patterns by lw
101- self ._us_dashes = None
100+
102101 self ._linewidth = 0
102+ self ._unscaled_dash_pattern = (0 , None ) # offset, dash
103+ self ._dash_pattern = (0 , None ) # offset, dash (scaled by linewidth)
103104
104105 self .set_fill (fill )
105106 self .set_linestyle (linestyle )
@@ -259,9 +260,8 @@ def update_from(self, other):
259260 self ._fill = other ._fill
260261 self ._hatch = other ._hatch
261262 self ._hatch_color = other ._hatch_color
262- # copy the unscaled dash pattern
263- self ._us_dashes = other ._us_dashes
264- self .set_linewidth (other ._linewidth ) # also sets dash properties
263+ self ._unscaled_dash_pattern = other ._unscaled_dash_pattern
264+ self .set_linewidth (other ._linewidth ) # also sets scaled dashes
265265 self .set_transform (other .get_data_transform ())
266266 # If the transform of other needs further initialization, then it will
267267 # be the case for this artist too.
@@ -407,12 +407,9 @@ def set_linewidth(self, w):
407407 w = mpl .rcParams ['patch.linewidth' ]
408408 if w is None :
409409 w = mpl .rcParams ['axes.linewidth' ]
410-
411410 self ._linewidth = float (w )
412- # scale the dash pattern by the linewidth
413- offset , ls = self ._us_dashes
414- self ._dashoffset , self ._dashes = mlines ._scale_dashes (
415- offset , ls , self ._linewidth )
411+ self ._dash_pattern = mlines ._scale_dashes (
412+ * self ._unscaled_dash_pattern , w )
416413 self .stale = True
417414
418415 def set_linestyle (self , ls ):
@@ -445,11 +442,9 @@ def set_linestyle(self, ls):
445442 if ls in [' ' , '' , 'none' ]:
446443 ls = 'None'
447444 self ._linestyle = ls
448- # get the unscaled dash pattern
449- offset , ls = self ._us_dashes = mlines ._get_dash_pattern (ls )
450- # scale the dash pattern by the linewidth
451- self ._dashoffset , self ._dashes = mlines ._scale_dashes (
452- offset , ls , self ._linewidth )
445+ self ._unscaled_dash_pattern = mlines ._get_dash_pattern (ls )
446+ self ._dash_pattern = mlines ._scale_dashes (
447+ * self ._unscaled_dash_pattern , self ._linewidth )
453448 self .stale = True
454449
455450 def set_fill (self , b ):
@@ -565,7 +560,7 @@ def _bind_draw_path_function(self, renderer):
565560 if self ._edgecolor [3 ] == 0 or self ._linestyle == 'None' :
566561 lw = 0
567562 gc .set_linewidth (lw )
568- gc .set_dashes (self ._dashoffset , self . _dashes )
563+ gc .set_dashes (* self ._dash_pattern )
569564 gc .set_capstyle (self ._capstyle )
570565 gc .set_joinstyle (self ._joinstyle )
571566
@@ -603,8 +598,9 @@ def draw(self, renderer):
603598 if not self .get_visible ():
604599 return
605600 # Patch has traditionally ignored the dashoffset.
606- with cbook ._setattr_cm (self , _dashoffset = 0 ), \
607- self ._bind_draw_path_function (renderer ) as draw_path :
601+ with cbook ._setattr_cm (
602+ self , _dash_pattern = (0 , self ._dash_pattern [1 ])), \
603+ self ._bind_draw_path_function (renderer ) as draw_path :
608604 path = self .get_path ()
609605 transform = self .get_transform ()
610606 tpath = transform .transform_path_non_affine (path )
0 commit comments