8000 Merge pull request #10592 from anntzer/unpackgen · matplotlib/matplotlib@ebe50c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit ebe50c1

Browse files
authored
Merge pull request #10592 from anntzer/unpackgen
Rely on generalized * and ** unpackings where possible.
2 parents c1eeb4c + d520128 commit ebe50c1

38 files changed

+171
-223
lines changed

examples/api/filled_step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
4848
Artist added to the Axes
4949
"""
5050
print(orientation)
51-
if orientation not in set('hv'):
51+
if orientation not in 'hv':
5252
raise ValueError("orientation must be in {{'h', 'v'}} "
5353
"not {o}".format(o=orientation))
5454

examples/images_contours_and_fields/custom_cmap.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,13 @@
143143

144144
# Make a modified version of cdict3 with some transparency
145145
# in the middle of the range.
146-
cdict4 = cdict3.copy()
147-
cdict4['alpha'] = ((0.0, 1.0, 1.0),
146+
cdict4 = {**cdict3,
147+
'alpha': ((0.0, 1.0, 1.0),
148148
# (0.25,1.0, 1.0),
149-
(0.5, 0.3, 0.3),
149+
(0.5, 0.3, 0.3),
150150
# (0.75,1.0, 1.0),
151-
(1.0, 1.0, 1.0))
151+
(1.0, 1.0, 1.0)),
152+
}
152153

153154

154155
###############################################################################

examples/mplot3d/polys3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def polygon_under_graph(xlist, ylist):
3030
Construct the vertex list which defines the polygon filling the space under
3131
the (xlist, ylist) line graph. Assumes the xs are in ascending order.
3232
'''
33-
return [(xlist[0], 0.)] + list(zip(xlist, ylist)) + [(xlist[-1], 0.)]
33+
return [(xlist[0], 0.), *zip(xlist, ylist), (xlist[-1], 0.)]
3434

3535

3636
fig = plt.figure()

examples/showcase/integral.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def func(x):
3232
# Make the shaded region
3333
ix = np.linspace(a, b)
3434
iy = func(ix)
35-
verts = [(a, 0)] + list(zip(ix, iy)) + [(b, 0)]
35+
verts = [(a, 0), *zip(ix, iy), (b, 0)]
3636
poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
3737
ax.add_patch(poly)
3838

examples/subplots_axes_and_figures/axes_zoom_effect.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
================
55
66
"""
7-
from matplotlib.transforms import Bbox, TransformedBbox, \
8-
blended_transform_factory
7+
from matplotlib.transforms import (
8+
Bbox, TransformedBbox, blended_transform_factory)
99

10-
from mpl_toolkits.axes_grid1.inset_locator import BboxPatch, BboxConnector,\
11-
BboxConnectorPatch
10+
from mpl_toolkits.axes_grid1.inset_locator import (
11+
BboxPatch, BboxConnector, BboxConnectorPatch)
1212

1313

1414
def connect_bbox(bbox1, bbox2,
1515
loc1a, loc2a, loc1b, loc2b,
1616
prop_lines, prop_patches=None):
1717
if prop_patches is None:
18-
prop_patches = prop_lines.copy()
19-
prop_patches["alpha"] = prop_patches.get("alpha", 1) * 0.2
18+
prop_patches = {
19+
**prop_lines,
20+
"alpha": prop_lines.get("alpha", 1) * 0.2,
21+
}
2022

2123
c1 = BboxConnector(bbox1, bbox2, loc1=loc1a, loc2=loc2a, **prop_lines)
2224
c1.set_clip_on(False)
@@ -55,14 +57,12 @@ def zoom_effect01(ax1, ax2, xmin, xmax, **kwargs):
5557
mybbox1 = TransformedBbox(bbox, trans1)
5658
mybbox2 = TransformedBbox(bbox, trans2)
5759

58-
prop_patches = kwargs.copy()
59-
prop_patches["ec"] = "none"
60-
prop_patches["alpha"] = 0.2
60+
prop_patches = {**kwargs, "ec": "none", "alpha": 0.2}
6161

62-
c1, c2, bbox_patch1, bbox_patch2, p = \
63-
connect_bbox(mybbox1, mybbox2,
64-
loc1a=3, loc2a=2, loc1b=4, loc2b=1,
65-
prop_lines=kwargs, prop_patches=prop_patches)
62+
c1, c2, bbox_patch1, bbox_patch2, p = connect_bbox(
63+
mybbox1, mybbox2,
64+
loc1a=3, loc2a=2, loc1b=4, loc2b=1,
65+
prop_lines=kwargs, prop_patches=prop_patches)
6666

6767
ax1.add_patch(bbox_patch1)
6868
ax2.add_patch(bbox_patch2)
@@ -88,14 +88,12 @@ def zoom_effect02(ax1, ax2, **kwargs):
8888
< CE1B span class=pl-s1>mybbox1 = ax1.bbox
8989
mybbox2 = TransformedBbox(ax1.viewLim, trans)
9090

91-
prop_patches = kwargs.copy()
92-
prop_patches["ec"] = "none"
93-
prop_patches["alpha"] = 0.2
91+
prop_patches = {**kwargs, "ec": "none", "alpha": 0.2}
9492

95-
c1, c2, bbox_patch1, bbox_patch2, p = \
96-
connect_bbox(mybbox1, mybbox2,
97-
loc1a=3, loc2a=2, loc1b=4, loc2b=1,
98-
prop_lines=kwargs, prop_patches=prop_patches)
93+
c1, c2, bbox_patch1, bbox_patch2, p = connect_bbox(
94+
mybbox1, mybbox2,
95+
loc1a=3, loc2a=2, loc1b=4, loc2b=1,
96+
prop_lines=kwargs, prop_patches=prop_patches)
9997

10098
ax1.add_patch(bbox_patch1)
10199
ax2.add_patch(bbox_patch2)

examples/tests/backend_driver_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def report_missing(dir, flist):
315315
globstr = os.path.join(dir, '*.py')
316316
fnames = glob.glob(globstr)
317317

318-
pyfiles = {os.path.split(fullpath)[-1] for fullpath in set(fnames)}
318+
pyfiles = {os.path.split(fullpath)[-1] for fullpath in fnames}
319319

320320
exclude = set(excluded.get(dir, []))
321321
flist = set(flist)

lib/matplotlib/_constrained_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
161161
invTransFig = fig.transFigure.inverted().transform_bbox
162162

163163
# list of unique gridspecs that contain child axes:
164-
gss = set([])
164+
gss = set()
165165
for ax in fig.axes:
166166
if hasattr(ax, CE1B 'get_subplotspec'):
167167
gs = ax.get_subplotspec().get_gridspec()

lib/matplotlib/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ def _blit_clear(self, artists, bg_cache):
12711271
# Get a list of the axes that need clearing from the artists that
12721272
# have been drawn. Grab the appropriate saved background from the
12731273
# cache and restore.
1274-
axes = set(a.axes for a in artists)
1274+
axes = {a.axes for a in artists}
12751275
for a in axes:
12761276
if a in bg_cache:
12771277
a.figure.canvas.restore_region(bg_cache[a])

lib/matplotlib/axes/_axes.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,8 +3077,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
30773077
fmt_style_kwargs = {}
30783078
else:
30793079
fmt_style_kwargs = {k: v for k, v in
3080-
zip(('linestyle', 'marker', 'color'),
3081-
_process_plot_format(fmt)) if v is not None}
3080+
zip(('linestyle', 'marker', 'color'),
3081+
_process_plot_format(fmt))
3082+
if v is not None}
30823083
if fmt == 'none':
30833084
# Remove alpha=0 color that _process_plot_format returns
30843085
fmt_style_kwargs.pop('color')
@@ -3114,12 +3115,12 @@ def errorbar(self, x, y, yerr=None, xerr=None,
31143115
yerr = [yerr] * len(y)
31153116

31163117
# make the style dict for the 'normal' plot line
3117-
plot_line_style = dict(base_style)
3118-
plot_line_style.update(**kwargs)
3119-
if barsabove:
3120-
plot_line_style['zorder'] = kwargs['zorder'] - .1
3121-
else:
3122-
plot_line_style['zorder'] = kwargs['zorder'] + .1
3118+
plot_line_style = {
3119+
**base_style,
3120+
**kwargs,
3121+
'zorder': (kwargs['zorder'] - .1 if barsabove else
3122+
kwargs['zorder'] + .1),
3123+
}
31233124

31243125
# make the style dict for the line collections (the bars)
31253126
eb_lines_style = dict(base_style)
@@ -7689,8 +7690,8 @@ def matshow(self, Z, **kwargs):
76897690
nr, nc = Z.shape
76907691
kw = {'origin': 'upper',
76917692
'interpolation': 'nearest',
7692-
'aspect': 'equal'} # (already the imshow default)
7693-
kw.update(kwargs)
7693+
'aspect': 'equal', # (already the imshow default)
7694+
**kwargs}
76947695
im = self.imshow(Z, **kw)
76957696
self.title.set_y(1.05)
76967697
self.xaxis.tick_top()

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ def _setdefaults(self, defaults, *kwargs):
287287
kw[k] = defaults[k]
288288

289289
def _makeline(self, x, y, kw, kwargs):
290-
kw = kw.copy() # Don't modify the original kw.
291-
kw.update(kwargs)
290+
kw = {**kw, **kwargs} # Don't modify the original kw.
292291
default_dict = self._getdefaults(None, kw)
293292
self._setdefaults(default_dict, kw)
294293
seg = mlines.Line2D(x, y, **kw)
@@ -527,8 +526,7 @@ def __init__(self, fig, rect,
527526
if yscale:
528527
self.set_yscale(yscale)
529528

530-
if len(kwargs):
531-
self.update(kwargs)
529+
self.update(kwargs)
532530

533531
if self.xaxis is not None:
534532
self._xcid = self.xaxis.callbacks.connect(

0 commit comments

Comments
 (0)
0