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 34aee94

Browse filesBrowse files
authored
Merge pull request #10569 from anntzer/style
Various style fixes.
2 parents 59c39ed + 441a6bc commit 34aee94
Copy full SHA for 34aee94
Expand file treeCollapse file tree

27 files changed

+100
-159
lines changed

‎examples/event_handling/ginput_manual_clabel_sgskip.py

Copy file name to clipboardExpand all lines: examples/event_handling/ginput_manual_clabel_sgskip.py
+7-10Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def tellme(s):
4040

4141
plt.waitforbuttonpress()
4242

43-
happy = False
44-
while not happy:
43+
while True:
4544
pts = []
4645
while len(pts) < 3:
4746
tellme('Select 3 corners with mouse')
@@ -54,12 +53,12 @@ def tellme(s):
5453

5554
tellme('Happy? Key click for yes, mouse click for no')
5655

57-
happy = plt.waitforbuttonpress()
56+
if plt.waitforbuttonpress():
57+
break
5858

5959
# Get rid of fill
60-
if not happy:
61-
for p in ph:
62-
p.remove()
60+
for p in ph:
61+
p.remove()
6362

6463

6564
##################################################
@@ -88,13 +87,11 @@ def f(x, y, pts):
8887
tellme('Now do a nested zoom, click to begin')
8988
plt.waitforbuttonpress()
9089

91-
happy = False
92-
while not happy:
90+
while True:
9391
tellme('Select two corners of zoom, middle mouse button to finish')
9492
pts = np.asarray(plt.ginput(2, timeout=-1))
9593

96-
happy = len(pts) < 2
97-
if happy:
94+
if len(pts) < 2:
9895
break
9996

10097
pts = np.sort(pts, axis=0)

‎lib/matplotlib/afm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/afm.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def _parse_header(fh):
162162
try:
163163
d[key] = headerConverters[key](val)
164164
except ValueError:
165-
print('Value error parsing header in AFM:',
166-
key, val, file=sys.stderr)
165+
print('Value error parsing header in AFM:', key, val,
166+
file=sys.stderr)
167167
continue
168168
except KeyError:
169169
print('Found an unknown keyword in AFM header (was %r)' % key,

‎lib/matplotlib/animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/animation.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,11 @@ def _init_from_registry(cls):
761761
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
762762
try:
763763
hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
764-
'Software\\Imagemagick\\Current',
764+
r'Software\Imagemagick\Current',
765765
0, winreg.KEY_QUERY_VALUE | flag)
766766
binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
767767
winreg.CloseKey(hkey)
768-
binpath += '\\convert.exe'
768+
binpath += r'\convert.exe'
769769
break
770770
except Exception:
771771
binpath = ''

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def _init_toolbar(self):
507507

508508
for text, tooltip_text, image_file, callback in self.toolitems:
509509
if text is None:
510-
self.insert( Gtk.SeparatorToolItem(), -1 )
510+
self.insert(Gtk.SeparatorToolItem(), -1)
511511
continue
512512
fname = os.path.join(basedir, image_file + '.png')
513513
image = Gtk.Image()
@@ -654,14 +654,10 @@ def cb_cbox_changed (cbox, data=None):
654654
self.set_extra_widget(hbox)
655655

656656
def get_filename_from_user (self):
657-
while True:
658-
filename = None
659-
if self.run() != int(Gtk.ResponseType.OK):
660-
break
661-
filename = self.get_filename()
662-
break
663-
664-
return filename, self.ext
657+
if self.run() == int(Gtk.ResponseType.OK):
658+
return self.get_filename(), self.ext
659+
else:
660+
return None, self.ext
665661

666662

667663
class RubberbandGTK3(backend_tools.RubberbandBase):

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,8 +1804,8 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans,
18041804
simplify=False):
18051805
if len(vertices):
18061806
x, y = vertices[-2:]
1807-
if (x < 0 or y < 0 or
1808-
x > self.file.width * 72 or y > self.file.height * 72):
1807+
if not (0 <= x <= self.file.width * 72
1808+
and 0 <= y <= self.file.height * 72):
18091809
continue
18101810
dx, dy = x - lastx, y - lasty
18111811
output(1, 0, 0, 1, dx, dy, Op.concat_matrix,

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ def supports_ps2write(self):
129129
'b10': (1.26,1.76)}
130130

131131
def _get_papertype(w, h):
132-
keys = list(six.iterkeys(papersize))
133-
keys.sort()
134-
keys.reverse()
135-
for key in keys:
136-
if key.startswith('l'): continue
137-
pw, ph = papersize[key]
138-
if (w < pw) and (h < ph): return key
132+
for key, (pw, ph) in sorted(papersize.items(), reverse=True):
133+
if key.startswith('l'):
134+
continue
135+
if w < pw and h < ph:
136+
return key
139137
return 'a0'
140138

141139
def _num_to_str(val):
142-
if isinstance(val, six.string_types): return val
140+
if isinstance(val, six.string_types):
141+
return val
143142

144143
ival = int(val)
145144
if val == ival: return str(ival)

‎lib/matplotlib/backends/backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_svg.py
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,12 @@ def generate_transform(transform_list=[]):
231231
if len(transform_list):
232232
output = io.StringIO()
233233
for type, value in transform_list:
234-
if type == 'scale' and (value == (1.0,) or value == (1.0, 1.0)):
235-
continue
236-
if type == 'translate' and value == (0.0, 0.0):
237-
continue
238-
if type == 'rotate' and value == (0.0,):
234+
if (type == 'scale' and (value == (1,) or value == (1, 1))
235+
or type == 'translate' and value == (0, 0)
236+
or type == 'rotate' and value == (0,)):
239237
continue
240238
if type == 'matrix' and isinstance(value, Affine2DBase):
241239
value = value.to_values()
242-
243240
output.write('%s(%s)' % (
244241
type, ' '.join(short_float_fmt(x) for x in value)))
245242
return output.getvalue()

‎lib/matplotlib/backends/backend_webagg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_webagg.py
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ def random_ports(port, n):
237237
for i in range(n - 5):
238238
yield port + random.randint(-2 * n, 2 * n)
239239

240-
success = None
241-
242240
if address is None:
243241
cls.address = rcParams['webagg.address']
244242
else:
@@ -252,10 +250,8 @@ def random_ports(port, n):
252250
raise
253251
else:
254252
cls.port = port
255-
success = True
256253
break
257-
258-
if not success:
254+
else:
259255
raise SystemExit(
260256
"The webagg server could not be started because an available "
261257
"port could not be found")

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,9 +1255,7 @@ def remove(self, o):
12551255
old = self._elements[:]
12561256
self.clear()
12571257
for thiso in old:
1258-
if thiso == o:
1259-
continue
1260-
else:
1258+
if thiso != o:
12611259
self.push(thiso)
12621260

12631261

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ def colorbar_factory(cax, mappable, **kwargs):
13881388
# if the given mappable is a contourset with any hatching, use
13891389
# ColorbarPatch else use Colorbar
13901390
if (isinstance(mappable, contour.ContourSet)
1391-
and any([hatch is not None for hatch in mappable.hatches])):
1391+
and any(hatch is not None for hatch in mappable.hatches)):
13921392
cb = ColorbarPatch(cax, mappable, **kwargs)
13931393
else:
13941394
cb = Colorbar(cax, mappable, **kwargs)

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,7 @@ def __init__(self, ax, *args, **kwargs):
861861
# extend_max case we don't need to worry about passing more colors
862862
# than ncolors as ListedColormap will clip.
863863
total_levels = ncolors + int(extend_min) + int(extend_max)
864-
if (len(self.colors) == total_levels and
865-
any([extend_min, extend_max])):
864+
if len(self.colors) == total_levels and (extend_min or extend_max):
866865
use_set_under_over = True
867866
if extend_min:
868867
i0 = 1

‎lib/matplotlib/dviread.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dviread.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ def __iter__(self):
238238
precision is not lost and coordinate values are not clipped to
239239
integers.
240240
"""
241-
while True:
242-
have_page = self._read()
243-
if have_page:
244-
yield self._output()
245-
else:
246-
break
241+
while self._read():
242+
yield self._output()
247243

248244
def close(self):
249245
"""

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,9 +1384,8 @@ def _break_share_link(ax, grouper):
13841384
if len(siblings) > 1:
13851385
grouper.remove(ax)
13861386
for last_ax in siblings:
1387-
if ax is last_ax:
1388-
continue
1389-
return last_ax
1387+
if ax is not last_ax:
1388+
return last_ax
13901389
return None
13911390

13921391
self.delaxes(ax)

‎lib/matplotlib/lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.py
+2-9Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,17 +1038,10 @@ def _split_drawstyle_linestyle(self, ls):
10381038
ls : str
10391039
The linestyle with the drawstyle (if any) stripped.
10401040
'''
1041-
ret_ds = None
10421041
for ds in self.drawStyleKeys: # long names are first in the list
10431042
if ls.startswith(ds):
1044-
ret_ds = ds
1045-
if len(ls) > len(ds):
1046-
ls = ls[len(ds):]
1047-
else:
1048-
ls = '-'
1049-
break
1050-
1051-
return ret_ds, ls
1043+
return ds, ls[len(ds):] or '-'
1044+
return None, ls
10521045

10531046
def set_linestyle(self, ls):
10541047
"""

‎lib/matplotlib/mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mathtext.py
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,17 +1552,17 @@ def __repr__(self):
15521552
self.depth, self.shift_amount,
15531553
' '.join([repr(x) for x in self.children]))
15541554

1555-
def _determine_order(self, totals):
1555+
@staticmethod
1556+
def _determine_order(totals):
15561557
"""
1557-
A helper function to determine the highest order of glue
1558-
used by the members of this list. Used by vpack and hpack.
1558+
Determine the highest order of glue used by the members of this list.
1559+
1560+
Helper function used by vpack and hpack.
15591561
"""
1560-
o = 0
1561-
for i in range(len(totals) - 1, 0, -1):
1562-
if totals[i] != 0.0:
1563-
o = i
1564-
break
1565-
return o
1562+
for i in range(len(totals))[::-1]:
1563+
if totals[i] != 0:
1564+
return i
1565+
return 0
15661566

15671567
def _set_glue(self, x, sign, totals, error_type):
15681568
o = self._determine_order(totals)

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+22-25Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import six
2424

25+
import inspect
2526
from numbers import Number
2627
import sys
2728
import time
@@ -1055,28 +1056,30 @@ def subplot(*args, **kwargs):
10551056
10561057
"""
10571058
# if subplot called without arguments, create subplot(1,1,1)
1058-
if len(args)==0:
1059-
args=(1,1,1)
1059+
if len(args) == 0:
1060+
args = (1, 1, 1)
10601061

10611062
# This check was added because it is very easy to type
10621063
# subplot(1, 2, False) when subplots(1, 2, False) was intended
10631064
# (sharex=False, that is). In most cases, no error will
10641065
# ever occur, but mysterious behavior can result because what was
10651066
# intended to be the sharex argument is instead treated as a
10661067
# subplot index for subplot()
1067-
if len(args) >= 3 and isinstance(args[2], bool) :
1068-
warnings.warn("The subplot index argument to subplot() appears"
1069-
" to be a boolean. Did you intend to use subplots()?")
1068+
if len(args) >= 3 and isinstance(args[2], bool):
1069+
warnings.warn("The subplot index argument to subplot() appears "
1070+
"to be a boolean. Did you intend to use subplots()?")
10701071

10711072
fig = gcf()
10721073
a = fig.add_subplot(*args, **kwargs)
10731074
bbox = a.bbox
10741075
byebye = []
10751076
for other in fig.axes:
1076-
if other==a: continue
1077+
if other == a:
1078+
continue
10771079
if bbox.fully_overlaps(other.bbox):
10781080
byebye.append(other)
1079-
for ax in byebye: delaxes(ax)
1081+
for ax in byebye:
1082+
delaxes(ax)
10801083

10811084
return a
10821085

@@ -1334,8 +1337,10 @@ def subplot_tool(targetfig=None):
13341337
else:
13351338
# find the manager for this figure
13361339
for manager in _pylab_helpers.Gcf._activeQue:
1337-
if manager.canvas.figure==targetfig: break
1338-
else: raise RuntimeError('Could not find manager for targetfig')
1340+
if manager.canvas.figure == targetfig:
1341+
break
1342+
else:
1343+
raise RuntimeError('Could not find manager for targetfig')
13391344

13401345
toolfig = figure(figsize=(6,3))
13411346
toolfig.subplots_adjust(top=0.9)
@@ -1845,27 +1850,19 @@ def get_plot_commands():
18451850
"""
18461851
Get a sorted list of all of the plotting commands.
18471852
"""
1848-
# This works by searching for all functions in this module and
1849-
# removing a few hard-coded exclusions, as well as all of the
1850-
# colormap-setting functions, and anything marked as private with
1851-
# a preceding underscore.
1852-
1853-
import inspect
1854-
1853+
# This works by searching for all functions in this module and removing
1854+
# a few hard-coded exclusions, as well as all of the colormap-setting
1855+
# functions, and anything marked as private with a preceding underscore.
18551856
exclude = {'colormaps', 'colors', 'connect', 'disconnect',
18561857
'get_plot_commands', 'get_current_fig_manager', 'ginput',
18571858
'plotting', 'waitforbuttonpress'}
18581859
exclude |= set(colormaps())
18591860
this_module = inspect.getmodule(get_plot_commands)
1860-
1861-
commands = set()
1862-
for name, obj in list(six.iteritems(globals())):
1863-
if name.startswith('_') or name in exclude:
1864-
continue
1865-
if inspect.isfunction(obj) and inspect.getmodule(obj) is this_module:
1866-
commands.add(name)
1867-
1868-
return sorted(commands)
1861+
return sorted(
1862+
name for name, obj in globals().items()
1863+
if not name.startswith('_') and name not in exclude
1864+
and inspect.isfunction(obj)
1865+
and inspect.getmodule(obj) is this_module)
18691866

18701867

18711868
@deprecated('2.1')

0 commit comments

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