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

Skip to content

Code style cleanup #16044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/images_contours_and_fields/contourf_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# A low hump with a spike coming out.
# Needs to have z/colour axis on a log scale so we see both hump and spike.
# linear scale only shows the spike.
Z1 = np.exp(-(X)**2 - (Y)**2)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
z = Z1 + 50 * Z2

Expand Down
2 changes: 1 addition & 1 deletion examples/images_contours_and_fields/pcolor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
# A low hump with a spike coming out.
# Needs to have z/colour axis on a log scale so we see both hump and spike.
# linear scale only shows the spike.
Z1 = np.exp(-(X)**2 - (Y)**2)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
Z = Z1 + 50 * Z2

Expand Down
4 changes: 2 additions & 2 deletions examples/text_labels_and_annotations/mathtext_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def doall():
plt.gca().set_yticklabels("", visible=False)

# Gap between lines in axes coords
line_axesfrac = (1. / (n_lines))
line_axesfrac = 1 / n_lines

# Plotting header demonstration formula
full_demo = mathext_demos[0]
Expand All @@ -82,7 +82,7 @@ def doall():

# Plotting features demonstration formulae
for i_line in range(1, n_lines):
baseline = 1 - (i_line) * line_axesfrac
baseline = 1 - i_line * line_axesfrac
baseline_next = baseline - line_axesfrac
title = mathtext_titles[i_line] + ":"
fill_color = ['white', mpl_blue_rvb][i_line % 2]
Expand Down
4 changes: 2 additions & 2 deletions examples/userdemo/colormap_normalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# z/colour axis on a log scale so we see both hump and spike. linear
# scale only shows the spike.

Z1 = np.exp(-(X)**2 - (Y)**2)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
Z = Z1 + 50 * Z2

Expand All @@ -41,7 +41,7 @@
# sine wave in Y. We can remove the power law using a PowerNorm.

X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
Z1 = (1 + np.sin(Y * 10.)) * X**(2.)
Z1 = (1 + np.sin(Y * 10.)) * X**2

fig, ax = plt.subplots(2, 1)

Expand Down
2 changes: 1 addition & 1 deletion examples/userdemo/colormap_normalizations_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
sine wave in Y. We can remove the power law using a PowerNorm.
'''
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
Z1 = (1 + np.sin(Y * 10.)) * X**(2.)
Z1 = (1 + np.sin(Y * 10.)) * X**2

fig, ax = plt.subplots(2, 1)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/_layoutbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,15 @@ def _is_subplotspec_layoutbox(self):
Helper to check if this layoutbox is the layoutbox of a
subplotspec
'''
name = (self.name).split('.')[-1]
name = self.name.split('.')[-1]
return name[:2] == 'ss'

def _is_gridspec_layoutbox(self):
'''
Helper to check if this layoutbox is the layoutbox of a
gridspec
'''
name = (self.name).split('.')[-1]
name = self.name.split('.')[-1]
return name[:8] == 'gridspec'

def find_child_subplots(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def correct_roundoff(x, dpi, n):

wnew = int(w * dpi / n) * n / dpi
hnew = int(h * dpi / n) * n / dpi
return (correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n))
return correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n)


# A registry for available MovieWriter classes
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def axes(self, new_axes):
self._axes = new_axes
if new_axes is not None and new_axes is not self:
self.stale_callback = _stale_axes_callback
return new_axes

@property
def stale(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def invert(x):
secax.set_xlabel('Period [s]')
plt.show()
"""
if (location in ['top', 'bottom'] or isinstance(location, Number)):
if location in ['top', 'bottom'] or isinstance(location, Number):
secondary_ax = SecondaryAxis(self, 'x', location, functions,
**kwargs)
self.add_child_axes(secondary_ax)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,7 @@ def tol(x): return 1e-5 * abs(x) + 1e-8
'minposy', self.yaxis, self._ymargin, y_stickies, self.set_ybound)

def _get_axis_list(self):
return (self.xaxis, self.yaxis)
return self.xaxis, self.yaxis

def _get_axis_map(self):
"""
Expand Down Expand Up @@ -3954,7 +3954,7 @@ def _get_view(self):
"""
xmin, xmax = self.get_xlim()
ymin, ymax = self.get_ylim()
return (xmin, xmax, ymin, ymax)
return xmin, xmax, ymin, ymax

def _set_view(self, view):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2876,7 +2876,7 @@ def press_zoom(self, event):
"""Callback for mouse button press in zoom to rect mode."""
# If we're already in the middle of a zoom, pressing another
# button works to "cancel"
if self._ids_zoom != []:
if self._ids_zoom:
for zoom_id in self._ids_zoom:
self.canvas.mpl_disconnect(zoom_id)
self.release(event)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def _press(self, event):

# If we're already in the middle of a zoom, pressing another
# button works to "cancel"
if self._ids_zoom != []:
if self._ids_zoom:
self._cancel_action()

if event.button == 1:
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,15 +1193,13 @@ def print_svg(self, filename, *args, **kwargs):
fh = TextIOWrapper(fh, 'utf-8')
detach = True

result = self._print_svg(filename, fh, **kwargs)
self._print_svg(filename, fh, **kwargs)

# Detach underlying stream from wrapper so that it remains open in
# the caller.
if detach:
fh.detach()

return result

def print_svgz(self, filename, *args, **kwargs):
with cbook.open_file_cm(filename, "wb") as fh, \
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ def _process_args(self, *args, **kwargs):
if (t != self.ax.transData and
any(t.contains_branch_seperately(self.ax.transData))):
trans_to_data = t - self.ax.transData
pts = (np.vstack([x.flat, y.flat]).T)
pts = np.vstack([x.flat, y.flat]).T
transformed_pts = trans_to_data.transform(pts)
x = transformed_pts[..., 0]
y = transformed_pts[..., 1]
Expand Down
19 changes: 9 additions & 10 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,16 +889,15 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
self._tz = tz
self.defaultfmt = defaultfmt
self._formatter = DateFormatter(self.defaultfmt, tz)
self.scaled = {DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
1.0: rcParams['date.autoformatter.day'],
1. / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
1. / (MINUTES_PER_DAY):
rcParams['date.autoformatter.minute'],
1. / (SEC_PER_DAY):
rcParams['date.autoformatter.second'],
1. / (MUSECONDS_PER_DAY):
rcParams['date.autoformatter.microsecond']}
self.scaled = {
DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
1: rcParams['date.autoformatter.day'],
1 / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
1 / MINUTES_PER_DAY: rcParams['date.autoformatter.minute'],
1 / SEC_PER_DAY: rcParams['date.autoformatter.second'],
1 / MUSECONDS_PER_DAY: rcParams['date.autoformatter.microsecond']
}

def _set_locator(self, locator):
self._locator = locator
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, hatch, density):
self.num_vertices = 0
else:
self.num_shapes = ((self.num_rows // 2 + 1) * (self.num_rows + 1) +
(self.num_rows // 2) * (self.num_rows))
(self.num_rows // 2) * self.num_rows)
self.num_vertices = (self.num_shapes *
len(self.shape_vertices) *
(1 if self.filled else 2))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def set_data(self, A):
raise TypeError("Image data of dtype {} cannot be converted to "
"float".format(self._A.dtype))

if (self._A.ndim == 3 and self._A.shape[-1] == 1):
if self._A.ndim == 3 and self._A.shape[-1] == 1:
# If just one dimension assume scalar and apply colormap
self._A = self._A[:, :, 0]

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer):
c = anchor_coefs[loc]

fontsize = renderer.points_to_pixels(self._fontsize)
container = parentbbox.padded(-(self.borderaxespad) * fontsize)
container = parentbbox.padded(-self.borderaxespad * fontsize)
anchored_box = bbox.anchored(c, container=container)
return anchored_box.x0, anchored_box.y0

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def _get_font(self, font):

def _get_offset(self, font, glyph, fontsize, dpi):
if font.postscript_name == 'Cmex10':
return ((glyph.height/64.0/2.0) + (fontsize/3.0 * dpi/72.0))
return (glyph.height / 64 / 2) + (fontsize/3 * dpi/72)
return 0.

def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
Expand Down Expand Up @@ -2025,7 +2025,7 @@ def __init__(self, c, height, depth, state, always=False, factor=None):
shift = 0
if state.font != 0:
if factor is None:
factor = (target_total) / (char.height + char.depth)
factor = target_total / (char.height + char.depth)
state.fontsize *= factor
char = Char(sym, state)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_align_labels():

for i in range(3):
ax = fig.add_subplot(gs[2, i])
ax.set_xlabel('XLabel2 %d' % (i))
ax.set_ylabel('YLabel2 %d' % (i))
ax.set_xlabel(f'XLabel2 {i}')
ax.set_ylabel(f'YLabel2 {i}')

if i == 2:
ax.plot(np.arange(0, 1e4, 10))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ def meshgrid_triangles(n):
tri = []
for i in range(n-1):
for j in range(n-1):
a = i + j*(n)
a = i + j*n
b = (i+1) + j*n
c = i + (j+1)*n
d = (i+1) + (j+1)*n
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,15 +1977,15 @@ def le(self, x):
'Return the largest n: n*step <= x.'
d, m = divmod(x, self.step)
if self.closeto(m / self.step, 1):
return (d + 1)
return d + 1
return d

def ge(self, x):
'Return the smallest n: n*step >= x.'
d, m = divmod(x, self.step)
if self.closeto(m / self.step, 0):
return d
return (d + 1)
return d + 1


class MaxNLocator(Locator):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tri/triinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ def compute_geom_weights(self):
weights = np.zeros([np.size(self._triangles, 0), 3])
tris_pts = self._tris_pts
for ipt in range(3):
p0 = tris_pts[:, (ipt) % 3, :]
p0 = tris_pts[:, ipt % 3, :]
p1 = tris_pts[:, (ipt+1) % 3, :]
p2 = tris_pts[:, (ipt-1) % 3, :]
alpha1 = np.arctan2(p1[:, 1]-p0[:, 1], p1[:, 0]-p0[:, 0])
Expand Down
6 changes: 3 additions & 3 deletions lib/mpl_toolkits/axisartist/axis_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def draw(self, renderer):
text_ref_angle = self._get_text_ref_angle()
offset_ref_angle = self._get_offset_ref_angle()

theta = (offset_ref_angle)/180.*np.pi
theta = np.deg2rad(offset_ref_angle)
dd = self._get_offset_radius()
dx, dy = dd * np.cos(theta), dd * np.sin(theta)
offset_tr.translate(dx, dy)
Expand All @@ -357,7 +357,7 @@ def get_window_extent(self, renderer):
text_ref_angle = self._get_text_ref_angle()
offset_ref_angle = self._get_offset_ref_angle()

theta = (offset_ref_angle)/180.*np.pi
theta = np.deg2rad(offset_ref_angle)
dd = self._get_offset_radius()
dx, dy = dd * np.cos(theta), dd * np.sin(theta)
offset_tr.translate(dx, dy)
Expand Down Expand Up @@ -722,7 +722,7 @@ def LABELPAD(self):

@LABELPAD.setter
def LABELPAD(self, v):
return self.label.set_pad(v)
self.label.set_pad(v)

def __init__(self, axes,
helper,
Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ def d_interval(self):

@d_interval.setter
def d_interval(self, minmax):
return self.set_data_interval(*minmax)
self.set_data_interval(*minmax)

@property
def v_interval(self):
return self.get_view_interval()

@d_interval.setter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually a bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to have a test for this...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should actually just deprecate them, as they are just mplot3d-specific synonyms for {get,set}_{view,data}_interval...

Copy link
Member Author

@timhoffm timhoffm Dec 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a separate PR #16053.

def v_interval(self, minmax):
return self.set_view_interval(*minmax)
self.set_view_interval(*minmax)


# Use classes to look at different data limits
Expand Down
4 changes: 2 additions & 2 deletions tutorials/colors/colormapnorms.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# A low hump with a spike coming out of the top right. Needs to have
# z/colour axis on a log scale so we see both hump and spike. linear
# scale only shows the spike.
Z1 = np.exp(-(X)**2 - (Y)**2)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
Z = Z1 + 50 * Z2

Expand Down Expand Up @@ -126,7 +126,7 @@

N = 100
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
Z1 = (1 + np.sin(Y * 10.)) * X**(2.)
Z1 = (1 + np.sin(Y * 10.)) * X**2

fig, ax = plt.subplots(2, 1)

Expand Down