8000 Merge pull request #11680 from anntzer/style · matplotlib/matplotlib@ac97e14 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac97e14

Browse files
authored
Merge pull request #11680 from anntzer/style
Boring style fixes.
2 parents 8b46f31 + a87445c commit ac97e14

File tree

21 files changed

+41
-45
lines changed

21 files changed

+41
-45
lines changed

examples/statistics/barchart_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def attach_ordinal(num):
7777
1 -> 1st
7878
56 -> 56th
7979
"""
80-
suffixes = dict((str(i), v) for i, v in
81-
enumerate(['th', 'st', 'nd', 'rd', 'th',
82-
'th', 'th', 'th', 'th', 'th']))
80+
suffixes = {str(i): v
81+
for i, v in enumerate(['th', 'st', 'nd', 'rd', 'th',
82+
'th', 'th', 'th', 'th', 'th'])}
8383

8484
v = str(num)
8585
# special case early teens
@@ -170,7 +170,7 @@ def plot_student_results(student, scores, cohort_size):
170170

171171
rankStr = attach_ordinal(width)
172172
# The bars aren't wide enough to print the ranking inside
173-
if (width < 5):
173+
if width < 5:
174174
# Shift the text to the right side of the right edge
175175
xloc = width + 1
176176
# Black against white background

examples/units/basic_units.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ def get_unit(self):
249249
class UnitResolver(object):
250250
def addition_rule(self, units):
251251
for unit_1, unit_2 in zip(units[:-1], units[1:]):
252-
if (unit_1 != unit_2):
252+
if unit_1 != unit_2:
253253
return NotImplemented
254254
return units[0]
255255

256256
def multiplication_rule(self, units):
257257
non_null = [u for u in units if u]
258-
if (len(non_null) > 1):
258+
if len(non_null) > 1:
259259
return NotImplemented
260260
return non_null[0]
261261

@@ -268,7 +268,7 @@ def multiplication_rule(self, units):
268268
'__rsub__': addition_rule}
269269

270270
def __call__(self, operation, units):
271-
if (operation not in self.op_dict):
271+
if operation not in self.op_dict:
272272
return NotImplemented
273273

274274
return self.op_dict[operation](self, units)

lib/matplotlib/backends/backend_ps.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,16 @@ def set_linedash(self, offset, seq, store=1):
266266
self.linedash = (offset, seq)
267267

268268
def set_font(self, fontname, fontsize, store=1):
269-
if rcParams['ps.useafm']: return
270-
if (fontname,fontsize) != (self.fontname,self.fontsize):
269+
if rcParams['ps.useafm']:
270+
return
271+
if (fontname, fontsize) != (self.fontname,self.fontsize):
271272
out = ("/%s findfont\n"
272273
"%1.3f scalefont\n"
273274
"setfont\n" % (fontname, fontsize))
274-
275275
self._pswriter.write(out)
276-
if store: self.fontname = fontname
277-
if store: self.fontsize = fontsize
276+
if store:
277+
self.fontname = fontname
278+
self.fontsize = fontsize
278279

279280
def create_hatch(self, hatch):
280281
sidelen = 72

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def delete_masked_points(*args):
10951095
"""
10961096
if not len(args):
10971097
return ()
1098-
if isinstance(args[0], str) or not iterable(args[0]):
1098+
if is_scalar_or_string(args[0]):
10991099
raise ValueError("First argument must be a sequence")
11001100
nrecs = len(args[0])
11011101
margs = []

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def set_verts(self, verts, closed=True):
964964

965965
def set_verts_and_codes(self, verts, codes):
966966
'''This allows one to initialize vertices with path codes.'''
967-
if (len(verts) != len(codes)):
967+
if len(verts) != len(codes):
968968
raise ValueError("'codes' must be a 1D list or array "
969969
"with the same length of 'verts'")
970970
self._paths = []

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,9 @@ def suptitle(self, t, **kwargs):
737737
x = kwargs.pop('x', 0.5)
738738
y = kwargs.pop('y', 0.98)
739739

740-
if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs):
740+
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs:
741741
kwargs['horizontalalignment'] = 'center'
742-
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
742+
if 'verticalalignment' not in kwargs and 'va' not in kwargs:
743743
kwargs['verticalalignment'] = 'top'
744744

745745
if 'fontproperties' not in kwargs:

lib/matplotlib/gridspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def __init__(self, nrows, ncols, figure=None,
212212
width_ratios=width_ratios,
213213
height_ratios=height_ratios)
214214

215-
if (self.figure is None) or not self.figure.get_constrained_layout():
215+
if self.figure is None or not self.figure.get_constrained_layout():
216216
self._layoutbox = None
217217
else:
218218
self.figure.init_layoutbox()

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
12421242

12431243
for handle in _get_legend_handles(axs, legend_handler_map):
12441244
label = handle.get_label()
1245-
if (label and not label.startswith('_')):
1245+
if label and not label.startswith('_'):
12461246
handles.append(handle)
12471247
labels.append(label)
12481248
return handles, labels

lib/matplotlib/lines.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,7 @@ def get_markeredgewidth(self):
882882
return self._markeredgewidth
883883

884884
def _get_markerfacecolor(self, alt=False):
885-
if alt:
886-
fc = self._markerfacecoloralt
887-
else:
888-
fc = self._markerfacecolor
885+
fc = self._markerfacecoloralt if alt else self._markerfacecolor
889886
if cbook._str_lower_equal(fc, 'auto'):
890887
if self.get_fillstyle() == 'none':
891888
return 'none'

lib/matplotlib/patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def __init__(self,
7171
self._hatch_color = colors.to_rgba(mpl.rcParams['hatch.color'])
7272
self._fill = True # needed for set_facecolor call
7373
if color is not None:
74-
if (edgecolor is not None or facecolor is not None):
74+
if edgecolor is not None or facecolor is not None:
7575
warnings.warn("Setting the 'color' property will override"
76-
"the edgecolor or facecolor properties. ")
76+
"the edgecolor or facecolor properties.")
7777
self.set_color(color)
7878
else:
7979
self.set_edgecolor(edgecolor)

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
131131

132132
if codes is not None:
133133
codes = np.asarray(codes, self.code_type)
134-
if (codes.ndim != 1) or len(codes) != len(vertices):
134+
if codes.ndim != 1 or len(codes) != len(vertices):
135135
raise ValueError("'codes' must be a 1D list or array with the "
136136
"same length of 'vertices'")
137137
if len(codes) and codes[0] != self.MOVETO:

lib/matplotlib/tests/test_patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_wedge_movement():
250250
'theta1': (0, 30, 'set_theta1'),
251251
'theta2': (45, 50, 'set_theta2')}
252252

253-
init_args = dict((k, v[0]) for (k, v) in param_dict.items())
253+
init_args = {k: v[0] for k, v in param_dict.items()}
254254

255255
w = mpatches.Wedge(**init_args)
256256
for attr, (old_v, new_v, func) in param_dict.items():

lib/matplotlib/tests/test_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def test_two_2line_texts(spacing1, spacing2):
435435

436436
# line spacing only affects height
437437
assert box1.width == box2.width
438-
if (spacing1 == spacing2):
438+
if spacing1 == spacing2:
439439
assert box1.height == box2.height
440440
else:
441441
assert box1.height != box2.height

lib/matplotlib/ticker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,26 +2410,26 @@ def tick_values(self, vmin, vmax):
24102410
ticklocs = []
24112411
if decade_min <= -1:
24122412
expo = np.arange(decade_min, min(0, decade_max + 1))
2413-
ticklocs.extend(list(10**expo))
2413+
ticklocs.extend(10**expo)
24142414
if decade_min <= 0 <= decade_max:
24152415
ticklocs.append(0.5)
24162416
if decade_max >= 1:
24172417
expo = -np.arange(max(1, decade_min), decade_max + 1)
2418-
ticklocs.extend(list(1 - 10**expo))
2418+
ticklocs.extend(1 - 10**expo)
24192419

24202420
# minor ticks
24212421
else:
24222422
ticklocs = []
24232423
if decade_min <= -2:
24242424
expo = np.arange(decade_min, min(-1, decade_max))
24252425
newticks = np.outer(np.arange(2, 10), 10**expo).ravel()
2426-
ticklocs.extend(list(newticks))
2426+
ticklocs.extend(newticks)
24272427
if decade_min <= 0 <= decade_max:
24282428
ticklocs.extend([0.2, 0.3, 0.4, 0.6, 0.7, 0.8])
24292429
if decade_max >= 2:
24302430
expo = -np.arange(max(2, decade_min), decade_max + 1)
24312431
newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel()
2432-
ticklocs.extend(list(newticks))
2432+
ticklocs.extend(newticks)
24332433

24342434
return self.raise_if_exceeds(np.array(ticklocs))
24352435

lib/matplotlib/tri/triinterpolate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def _interpolate_multikeys(self, x, y, tri_index=None,
175175
if tri_index is None:
176176
tri_index = self._trifinder(x, y)
177177
else:
178-
if (tri_index.shape != sh_ret):
178+
if tri_index.shape != sh_ret:
179179
raise ValueError(
180180
"tri_index array is provided and shall"
181181
" have same shape as x and y. Given: "

lib/matplotlib/widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def _update(self, event):
413413
event.canvas.release_mouse(self.ax)
414414
return
415415
val = self._value_in_bounds(event.xdata)
416-
if (val is not None) and (val != self.val):
416+
if val not in [None, self.val]:
417417
self.set_val(val)
418418

419419
def set_val(self, val):
@@ -474,7 +474,7 @@ def disconnect(self, cid):
474474

475475
def reset(self):
476476
"""Reset the slider to the initial value"""
477-
if (self.val != self.valinit):
477+
if self.val != self.valinit:
478478
self.set_val(self.valinit)
479479

480480

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(self, fig,
169169
if ngrids is None:
170170
ngrids = self._nrows * self._ncols
171171
else:
172-
if (ngrids > self._nrows * self._ncols) or (ngrids <= 0):
172+
if not 0 < ngrids <= self._nrows * self._ncols:
173173
raise Exception("")
174174

175175
self.ngrids = ngrids

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __init__(self, ticksize, tick_out=False, *, axis=None, **kwargs):
216216
if self._axis is not None:
217217
if "color" not in kwargs:
218218
kwargs["color"] = "auto"
219-
if ("mew" not in kwargs) and ("markeredgewidth" not in kwargs):
219+
if "mew" not in kwargs and "markeredgewidth" not in kwargs:
220220
kwargs["markeredgewidth"] = "auto"
221221

222222
Line2D.__init__(self, [0.], [0.], **kwargs)
@@ -1125,8 +1125,8 @@ def _draw_ticks(self, renderer):
11251125
self.minor_ticks.draw(renderer)
11261126
self.minor_ticklabels.draw(renderer)
11271127

1128-
1129-
if (self.major_ticklabels.get_visible() or self.minor_ticklabels.get_visible()):
1128+
if (self.major_ticklabels.get_visible()
1129+
or self.minor_ticklabels.get_visible()):
11301130
self._draw_offsetText(renderer)
11311131

11321132
return extents
@@ -1169,8 +1169,8 @@ def _draw_ticks2(self, renderer):
11691169
self.minor_ticks.draw(renderer)
11701170
self.minor_ticklabels.draw(renderer)
11711171

1172-
1173-
if (self.major_ticklabels.get_visible() or self.minor_ticklabels.get_visible()):
1172+
if (self.major_ticklabels.get_visible()
1173+
or self.minor_ticklabels.get_visible()):
11741174
self._draw_offsetText(renderer)
11751175

11761176
return self.major_ticklabels.get_window_extents(renderer)

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def get_axislabel_pos_angle(self, axes):
6666
trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
6767
p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]])
6868

69-
70-
if (0. <= p[0] <= 1.) and (0. <= p[1] <= 1.):
69+
if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:
7170
xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]])
7271
xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy])
7372
xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]])

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ def get_axislabel_pos_angle(self, axes):
175175
trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
176176
p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]])
177177

178-
179-
if (0. <= p[0] <= 1.) and (0. <= p[1] <= 1.):
178+
if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:
180179
xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]])
181180
xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy])
182181
xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]])

setupext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def _check_for_pkg_config(self, package, include_file, min_version=None,
478478
"Requires patches that have not been merged upstream.")
479479

480480
if min_version and version != 'unknown':
481-
if (not is_min_version(version, min_version)):
481+
if not is_min_version(version, min_version):
482482
raise CheckFailed(
483483
"Requires %s %s or later. Found %s." %
484484
(package, min_version, version))

0 commit comments

Comments
 (0)
0