Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2a5e22

Browse files
authored
Merge pull request #21698 from anntzer/style
STY: Small code cleanups and style fixes.
2 parents 17f4d19 + ff30378 commit c2a5e22

18 files changed

+54
-85
lines changed

examples/axisartist/demo_floating_axis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def curvelinear_test2(fig):
2929
lon_cycle=360,
3030
lat_cycle=None,
3131
lon_minmax=None,
32-
lat_minmax=(0,
33-
np.inf),
32+
lat_minmax=(0, np.inf),
3433
)
3534

3635
grid_locator1 = angle_helper.LocatorDMS(12)

lib/matplotlib/backends/backend_wx.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,11 @@ def _get_key(self, event):
714714
else:
715715
key = None
716716

717-
for meth, prefix, key_name in (
718-
[event.ControlDown, 'ctrl', 'control'],
719-
[event.AltDown, 'alt', 'alt'],
720-
[event.ShiftDown, 'shift', 'shift'],):
717+
for meth, prefix, key_name in [
718+
(event.ControlDown, 'ctrl', 'control'),
719+
(event.AltDown, 'alt', 'alt'),
720+
(event.ShiftDown, 'shift', 'shift'),
721+
]:
721722
if meth() and key_name != key:
722723
if not (key_name == 'shift' and key.isupper()):
723724
key = '{0}+{1}'.format(prefix, key)

lib/matplotlib/cbook/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ class CallbackRegistry:
146146
drink 123
147147
>>> callbacks.process('eat', 456)
148148
eat 456
149-
>>> callbacks.process('be merry', 456) # nothing will be called
149+
>>> callbacks.process('be merry', 456) # nothing will be called
150150
151151
>>> callbacks.disconnect(id_eat)
152-
>>> callbacks.process('eat', 456) # nothing will be called
152+
>>> callbacks.process('eat', 456) # nothing will be called
153153
154154
>>> with callbacks.blocked(signal='drink'):
155-
... callbacks.process('drink', 123) # nothing will be called
155+
... callbacks.process('drink', 123) # nothing will be called
156156
>>> callbacks.process('drink', 123)
157157
drink 123
158158
@@ -948,7 +948,7 @@ def delete_masked_points(*args):
948948
else:
949949
x = np.asarray(x)
950950
margs.append(x)
951-
masks = [] # list of masks that are True where good
951+
masks = [] # List of masks that are True where good.
952952
for i, x in enumerate(margs):
953953
if seqlist[i]:
954954
if x.ndim > 1:

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
486486
if np.iterable(ticks):
487487
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
488488
else:
489-
self.locator = ticks # Handle default in _ticker()
489+
self.locator = ticks # Handle default in _ticker()
490490

491491
if isinstance(format, str):
492492
# Check format between FormatStrFormatter and StrMethodFormatter

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ def __call__(self, value, clip=None):
12361236
(vmin,), _ = self.process_value(self.vmin)
12371237
(vmax,), _ = self.process_value(self.vmax)
12381238
if vmin == vmax:
1239-
result.fill(0) # Or should it be all masked? Or 0.5?
1239+
result.fill(0) # Or should it be all masked? Or 0.5?
12401240
elif vmin > vmax:
12411241
raise ValueError("minvalue must be less than or equal to maxvalue")
12421242
else:

lib/matplotlib/dates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ def get_unit_generic(freq):
12241224
return 1.0 / SEC_PER_DAY
12251225
else:
12261226
# error
1227-
return -1 # or should this just return '1'?
1227+
return -1 # or should this just return '1'?
12281228

12291229
def _get_interval(self):
12301230
return self.rule._rrule._interval
@@ -1377,7 +1377,7 @@ def get_locator(self, dmin, dmax):
13771377
# whenever possible.
13781378
numYears = float(delta.years)
13791379
numMonths = numYears * MONTHS_PER_YEAR + delta.months
1380-
numDays = tdelta.days # Avoids estimates of days/month, days/year
1380+
numDays = tdelta.days # Avoids estimates of days/month, days/year.
13811381
numHours = numDays * HOURS_PER_DAY + delta.hours
13821382
numMinutes = numHours * MIN_PER_HOUR + delta.minutes
13831383
numSeconds = np.floor(tdelta.total_seconds())

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,7 @@ def clf(self, keep_observers=False):
27562756

27572757
for ax in tuple(self.axes): # Iterate over the copy.
27582758
ax.cla()
2759-
self.delaxes(ax) # removes ax from self._axstack
2759+
self.delaxes(ax) # Remove ax from self._axstack.
27602760

27612761
toolbar = getattr(self.canvas, 'toolbar', None)
27622762
if toolbar is not None:

lib/matplotlib/mathtext.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,11 @@ def to_rgba(self, texstr, color='black', dpi=120, fontsize=14):
506506
depth : int
507507
Offset of the baseline from the bottom of the image, in pixels.
508508
"""
509-
x, depth = self.to_mask(texstr, dpi=dpi, fontsize=fontsize)
510-
511-
r, g, b, a = mcolors.to_rgba(color)
512-
RGBA = np.zeros((x.shape[0], x.shape[1], 4), dtype=np.uint8)
513-
RGBA[:, :, 0] = 255 * r
514-
RGBA[:, :, 1] = 255 * g
515-
RGBA[:, :, 2] = 255 * b
516-
RGBA[:, :, 3] = x
517-
return RGBA, depth
509+
alpha, depth = self.to_mask(texstr, dpi=dpi, fontsize=fontsize)
510+
rgba = np.zeros((alpha.shape[0], alpha.shape[1], 4), dtype=np.uint8)
511+
rgba[:] = 255 * np.asarray(mcolors.to_rgba(color))
512+
rgba[:, :, 3] = alpha
513+
return rgba, depth
518514

519515
@_api.deprecated("3.4", alternative="mathtext.math_to_image")
520516
def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):

lib/matplotlib/offsetbox.py

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,11 @@ def draw(self, renderer):
356356
Update the location of children if necessary and draw them
357357
to the given *renderer*.
358358
"""
359-
width, height, xdescent, ydescent, offsets = self.get_extent_offsets(
360-
renderer)
361-
362-
px, py = self.get_offset(width, height, xdescent, ydescent, renderer)
363-
359+
w, h, xdescent, ydescent, offsets = self.get_extent_offsets(renderer)
360+
px, py = self.get_offset(w, h, xdescent, ydescent, renderer)
364361
for c, (ox, oy) in zip(self.get_visible_children(), offsets):
365362
c.set_offset((px + ox, py + oy))
366363
c.draw(renderer)
367-
368364
bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
369365
self.stale = False
370366

@@ -541,11 +537,8 @@ def get_extent_offsets(self, renderer):
541537

542538
def draw(self, renderer):
543539
# docstring inherited
544-
width, height, xdescent, ydescent, offsets = self.get_extent_offsets(
545-
renderer)
546-
547-
px, py = self.get_offset(width, height, xdescent, ydescent, renderer)
548-
540+
w, h, xdescent, ydescent, offsets = self.get_extent_offsets(renderer)
541+
px, py = self.get_offset(w, h, xdescent, ydescent, renderer)
549542
for c, (ox, oy) in zip(self.get_visible_children(), offsets):
550543
c.set_offset((px + ox, py + oy))
551544

@@ -576,8 +569,7 @@ class DrawingArea(OffsetBox):
576569
boundaries of the parent.
577570
"""
578571

579-
def __init__(self, width, height, xdescent=0.,
580-
ydescent=0., clip=False):
572+
def __init__(self, width, height, xdescent=0., ydescent=0., clip=False):
581573
"""
582574
Parameters
583575
----------
@@ -1055,8 +1047,7 @@ def get_bbox_to_anchor(self):
10551047
if transform is None:
10561048
return self._bbox_to_anchor
10571049
else:
1058-
return TransformedBbox(self._bbox_to_anchor,
1059-
transform)
1050+
return TransformedBbox(self._bbox_to_anchor, transform)
10601051

10611052
def set_bbox_to_anchor(self, bbox, transform=None):
10621053
"""
@@ -1342,22 +1333,12 @@ def __init__(self, offsetbox, xy,
13421333
xy,
13431334
xycoords=xycoords,
13441335
annotation_clip=annotation_clip)
1345-
13461336
self.offsetbox = offsetbox
1347-
13481337
self.arrowprops = arrowprops
1349-
13501338
self.set_fontsize(fontsize)
1351-
1352-
if xybox is None:
1353-
self.xybox = xy
1354-
else:
1355-
self.xybox = xybox
1356-
1357-
if boxcoords is None:
1358-
self.boxcoords = xycoords
1359-
else:
1360-
self.boxcoords = boxcoords
1339+
self.xybox = xybox if xybox is not None else xy
1340+
self.boxcoords = boxcoords if boxcoords is not None else xycoords
1341+
self._box_alignment = box_alignment
13611342

13621343
if arrowprops is not None:
13631344
self._arrow_relpos = self.arrowprops.pop("relpos", (0.5, 0.5))
@@ -1367,10 +1348,7 @@ def __init__(self, offsetbox, xy,
13671348
self._arrow_relpos = None
13681349
self.arrow_patch = None
13691350

1370-
self._box_alignment = box_alignment
1371-
1372-
# frame
1373-
self.patch = FancyBboxPatch(
1351+
self.patch = FancyBboxPatch( # frame
13741352
xy=(0.0, 0.0), width=1., height=1.,
13751353
facecolor='w', edgecolor='k',
13761354
mutation_scale=self.prop.get_size_in_points(),
@@ -1488,28 +1466,24 @@ def _update_position_xybox(self, renderer, xy_pixel):
14881466
bbox = self.offsetbox.get_window_extent(renderer)
14891467
self.patch.set_bounds(bbox.bounds)
14901468

1491-
x, y = xy_pixel
1492-
1493-
ox1, oy1 = x, y
1469+
ox1, oy1 = xy_pixel
14941470

14951471
if self.arrowprops:
14961472
d = self.arrowprops.copy()
14971473

14981474
# Use FancyArrowPatch if self.arrowprops has "arrowstyle" key.
14991475

1500-
# adjust the starting point of the arrow relative to
1501-
# the textbox.
1502-
# TODO : Rotation needs to be accounted.
1476+
# Adjust the starting point of the arrow relative to the textbox.
1477+
# TODO: Rotation needs to be accounted.
15031478
relpos = self._arrow_relpos
15041479

15051480
ox0 = bbox.x0 + bbox.width * relpos[0]
15061481
oy0 = bbox.y0 + bbox.height * relpos[1]
15071482

1508-
# The arrow will be drawn from (ox0, oy0) to (ox1,
1509-
# oy1). It will be first clipped by patchA and patchB.
1510-
# Then it will be shrunk by shrinkA and shrinkB
1511-
# (in points). If patch A is not set, self.bbox_patch
1512-
# is used.
1483+
# The arrow will be drawn from (ox0, oy0) to (ox1, oy1).
1484+
# It will be first clipped by patchA and patchB.
1485+
# Then it will be shrunk by shrinkA and shrinkB (in points).
1486+
# If patch A is not set, self.bbox_patch is used.
15131487

15141488
self.arrow_patch.set_positions((ox0, oy0), (ox1, oy1))
15151489
fs = self.prop.get_size_in_points()

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def draw():
956956
def savefig(*args, **kwargs):
957957
fig = gcf()
958958
res = fig.savefig(*args, **kwargs)
959-
fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors
959+
fig.canvas.draw_idle() # Need this if 'transparent=True', to reset colors.
960960
return res
961961

962962

lib/matplotlib/rcsetup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,11 @@ def validate_cycler(s):
744744
for prop in cycler_inst.keys:
745745
norm_prop = _prop_aliases.get(prop, prop)
746746
if norm_prop != prop and norm_prop in cycler_inst.keys:
747-
raise ValueError("Cannot specify both '{0}' and alias '{1}'"
748-
" in the same prop_cycle".format(norm_prop, prop))
747+
raise ValueError(f"Cannot specify both {norm_prop!r} and alias "
748+
f"{prop!r} in the same prop_cycle")
749749
if norm_prop in checker:
750-
raise ValueError("Another property was already aliased to '{0}'."
751-
" Collision normalizing '{1}'.".format(norm_prop,
752-
prop))
750+
raise ValueError(f"Another property was already aliased to "
751+
f"{norm_prop!r}. Collision normalizing {prop!r}.")
753752
checker.update([norm_prop])
754753

755754
# This is just an extra-careful check, just in case there is some

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_bbox_inches_tight():
2424
rows = len(data)
2525
ind = np.arange(len(col_labels)) + 0.3 # the x locations for the groups
2626
cell_text = []
27-
width = 0.4 # the width of the bars
27+
width = 0.4 # the width of the bars
2828
yoff = np.zeros(len(col_labels))
2929
# the bottom values for stacked bar chart
3030
fig, ax = plt.subplots(1, 1)

lib/matplotlib/tests/test_dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def _test_date2num_dst(date_range, tz_convert):
878878
# Interval is 0b0.0000011 days, to prevent float rounding issues
879879
dtstart = datetime.datetime(2014, 3, 30, 0, 0, tzinfo=UTC)
880880
interval = datetime.timedelta(minutes=33, seconds=45)
881-
interval_days = 0.0234375 # 2025 / 86400 seconds
881+
interval_days = interval.seconds / 86400
882882
N = 8
883883

884884
dt_utc = date_range(start=dtstart, freq=interval, periods=N)

lib/matplotlib/tests/test_patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def test_datetime_datetime_fails():
487487
from datetime import datetime
488488

489489
start = datetime(2017, 1, 1, 0, 0, 0)
490-
dt_delta = datetime(1970, 1, 5) # Will be 5 days if units are done wrong
490+
dt_delta = datetime(1970, 1, 5) # Will be 5 days if units are done wrong.
491491

492492
with pytest.raises(TypeError):
493493
mpatches.Rectangle((start, 0), dt_delta, 1)

lib/matplotlib/tests/test_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_annotation_contains():
240240
fig, ax = plt.subplots()
241241
ann = ax.annotate(
242242
"hello", xy=(.4, .4), xytext=(.6, .6), arrowprops={"arrowstyle": "->"})
243-
fig.canvas.draw() # Needed for the same reason as in test_contains.
243+
fig.canvas.draw() # Needed for the same reason as in test_contains.
244244
event = MouseEvent(
245245
"button_press_event", fig.canvas, *ax.transData.transform((.5, .6)))
246246
assert ann.contains(event) == (False, {})

lib/matplotlib/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(self,
154154
self._bbox_patch = None # a FancyBboxPatch instance
155155
self._renderer = None
156156
if linespacing is None:
157-
linespacing = 1.2 # Maybe use rcParam later.
157+
linespacing = 1.2 # Maybe use rcParam later.
158158
self._linespacing = linespacing
159159
self.set_rotation_mode(rotation_mode)
160160
self.update(kwargs)
@@ -1976,7 +1976,7 @@ def draw(self, renderer):
19761976
# FancyArrowPatch is correctly positioned.
19771977
self.update_positions(renderer)
19781978
self.update_bbox_position_size(renderer)
1979-
if self.arrow_patch is not None: # FancyArrowPatch
1979+
if self.arrow_patch is not None: # FancyArrowPatch
19801980
if self.arrow_patch.figure is None and self.figure is not None:
19811981
self.arrow_patch.figure = self.figure
19821982
self.arrow_patch.draw(renderer)

lib/matplotlib/ticker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,13 +1412,13 @@ def format_eng(self, num):
14121412
representing the power of 1000 of the original number.
14131413
Some examples:
14141414
1415-
>>> format_eng(0) # for self.places = 0
1415+
>>> format_eng(0) # for self.places = 0
14161416
'0'
14171417
1418-
>>> format_eng(1000000) # for self.places = 1
1418+
>>> format_eng(1000000) # for self.places = 1
14191419
'1.0 M'
14201420
1421-
>>> format_eng("-1e-6") # for self.places = 2
1421+
>>> format_eng("-1e-6") # for self.places = 2
14221422
'-1.00 \N{MICRO SIGN}'
14231423
"""
14241424
sign = 1

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class Axis(maxis.XAxis):
3636
"""An Axis class for the 3D plots."""
3737
# These points from the unit cube make up the x, y and z-planes
3838
_PLANES = (
39-
(0, 3, 7, 4), (1, 2, 6, 5), # yz planes
40-
(0, 1, 5, 4), (3, 2, 6, 7), # xz planes
41-
(0, 1, 2, 3), (4, 5, 6, 7), # xy planes
39+
(0, 3, 7, 4), (1, 2, 6, 5), # yz planes
40+
(0, 1, 5, 4), (3, 2, 6, 7), # xz planes
41+
(0, 1, 2, 3), (4, 5, 6, 7), # xy planes
4242
)
4343

4444
# Some properties for the axes

0 commit comments

Comments
 (0)