@@ -28,6 +28,7 @@ def legend_artist(self, legend, orig_handle, fontsize, handlebox)
2828
2929import numpy as np
3030
31+ from matplotlib import cbook
3132from matplotlib .lines import Line2D
3233from matplotlib .patches import Rectangle
3334import matplotlib .collections as mcoll
@@ -607,19 +608,15 @@ def create_artists(self, legend, orig_handle,
607608 if using_linecoll :
608609 # change the function used by update_prop() from the default
609610 # to one that handles LineCollection
610- orig_update_func = self ._update_prop_func
611- self ._update_prop_func = self ._copy_collection_props
612-
613- for line in leg_stemlines :
614- self .update_prop (line , stemlines , legend )
611+ with cbook ._setattr_cm (
612+ self , _update_prop_func = self ._copy_collection_props ):
613+ for line in leg_stemlines :
614+ self .update_prop (line , stemlines , legend )
615615
616616 else :
617617 for lm , m in zip (leg_stemlines , stemlines ):
618618 self .update_prop (lm , m , legend )
619619
620- if using_linecoll :
621- self ._update_prop_func = orig_update_func
622-
623620 leg_baseline = Line2D ([np .min (xdata ), np .max (xdata )],
624621 [bottom , bottom ])
625622 self .update_prop (leg_baseline , baseline , legend )
0 commit comments