Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8459a5

Browse filesBrowse files
committed
Use cbook._setattr_cm more.
1 parent ce9c860 commit f8459a5
Copy full SHA for f8459a5

File tree

Expand file treeCollapse file tree

3 files changed

+16
-24
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-24
lines changed

‎lib/matplotlib/legend_handler.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend_handler.py
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def legend_artist(self, legend, orig_handle, fontsize, handlebox)
2828

2929
import numpy as np
3030

31+
from matplotlib import cbook
3132
from matplotlib.lines import Line2D
3233
from matplotlib.patches import Rectangle
3334
import 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)

‎lib/matplotlib/quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/quiver.py
+9-12Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,15 @@ def _init(self):
306306
if not self.Q._initialized:
307307
self.Q._init()
308308
self._set_transform()
309-
_pivot = self.Q.pivot
310-
self.Q.pivot = self.pivot[self.labelpos]
311-
# Hack: save and restore the Umask
312-
_mask = self.Q.Umask
313-
self.Q.Umask = ma.nomask
314-
u = self.U * np.cos(np.radians(self.angle))
315-
v = self.U * np.sin(np.radians(self.angle))
316-
angle = self.Q.angles if isinstance(self.Q.angles, str) else 'uv'
317-
self.verts = self.Q._make_verts(
318-
np.array([u]), np.array([v]), angle)
319-
self.Q.Umask = _mask
320-
self.Q.pivot = _pivot
309+
with cbook._setattr_cm(self.Q, pivot=self.pivot[self.labelpos],
310+
# Hack: save and restore the Umask
311+
Umask=ma.nomask):
312+
u = self.U * np.cos(np.radians(self.angle))
313+
v = self.U * np.sin(np.radians(self.angle))
314+
angle = (self.Q.angles if isinstance(self.Q.angles, str)
315+
else 'uv')
316+
self.verts = self.Q._make_verts(
317+
np.array([u]), np.array([v]), angle)
321318
kw = self.Q.polykw
322319
kw.update(self.kw)
323320
self.vector = mcollections.PolyCollection(

‎lib/matplotlib/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/widgets.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,8 @@ def __init__(self, targetfig, toolfig):
11511151

11521152
# During reset there can be a temporary invalid state depending on the
11531153
# order of the reset so we turn off validation for the resetting
1154-
validate = toolfig.subplotpars.validate
1155-
toolfig.subplotpars.validate = False
1156-
self.buttonreset.on_clicked(self._on_reset)
1157-
toolfig.subplotpars.validate = validate
1154+
with cbook._setattr_cm(toolfig.subplotpars, validate=False):
1155+
self.buttonreset.on_clicked(self._on_reset)
11581156

11591157
def _on_slider_changed(self, _):
11601158
self.targetfig.subplots_adjust(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.